I have a string representation of an array:
'["item1", "item2", "item3"]'
I'm trying to convert this back to an array.
Any pointers appreciated.
The String. split() method converts a string into an array of substrings using a separator and returns a new array. It splits the string every time it matches against the given separator. You can also optionally pass in an integer as a second parameter to specify the number of splits.
To convert an array of numbers to an array of strings, call the map() method on the array, and on each iteration, convert the number to a string. The map method will return a new array containing only strings.
String str = "Tutorial"; Now, use the toCharArray() method to convert string to char array. char[] ch = str. toCharArray();
The string in JavaScript can be converted into a character array by using the split() and Array. from() functions.
Just use JSON.parse('["item1", "item2", "item3"]');
Try JSON.parse:
ary = JSON.parse(s);
Most browsers support it natively, for others you'll need json.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With