C
C
colorkid2016-11-01 16:37:17
JavaScript
colorkid, 2016-11-01 16:37:17

Does not convert a string to an array. Why? How to convert?

Hello.
Faced such a problem.
1. There is a JSON file consisting of {
"category": "moykistal",
"name": "Polygran F-05 sink",
"price": 2990,
"preview": "img/f05beige-min.png",
"photos ":
[
"f05beige-min.png",
"f05black-min.png",
"f05green-min.png",
"f05pink-min.png"
],
"description": "Any, absolutely any text, of course, is better, so that it would be information about the product "
},
2. I merge pictures from photos into the data attribute data-photos.
3.
4. I want to convert the given string to an Array using var arr = names.split('///'); I put the separator /// for clarity
BUT I check arr still f05green-min.png, f05beige-min.png, f05black-min.png, f05pink-min.png without ///. And the typeof check shows the object.
Tell me how to make it so that there is a regular array [f05green-min.png, f05beige-min.png, f05black-min.png, f05pink-min.png] ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Олег, 2016-11-01
@werty1001

https://jsfiddle.net/werty1001/v0cfgzta/
В JS массив при проверке typeof будет объектом - это нормально, это особенности языка.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question