-4

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

How do I change that String into type Array?

3
  • JSON.parse('["123", 123, "testing"]') Commented Nov 15, 2019 at 21:17
  • If that's the format of your string, then just JSON.parse it. However, your nearly-identical previous question showed the array in a different format... Commented Nov 15, 2019 at 21:18
  • 1
    What have you tried, and what exactly is the problem with it? Commented Nov 15, 2019 at 21:21

1 Answer 1

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]);
}

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.