-4

I have a type String that looks like '["123", 123, "testing"]'.

How do I change that String into type Array?

Erik Åsland
  • 9,542
  • 10
  • 30
  • 58
  • `JSON.parse('["123", 123, "testing"]')` – Dalorzo Nov 15 '19 at 21:17
  • If that's the format of your string, then just `JSON.parse` it. However, [*your nearly-identical previous question*](https://stackoverflow.com/questions/58883897/how-do-i-determine-if-a-string-is-an-array) showed the array in a different format... – Tyler Roper Nov 15 '19 at 21:18
  • 1
    What have you tried, and what exactly is the problem with it? – jonrsharpe Nov 15 '19 at 21:21

1 Answers1

0

You can use JSON.parse. See example below:

var str = '["123", 123, "testing"]';
var strArray = JSON.parse(str);
console.log(strArray);

for(var i = 0; i < strArray.length; i++) {
  console.log(strArray[i]);
}
Word Rearranger
  • 1,306
  • 1
  • 16
  • 25