How to transform a string of this format '[11, 66]' to an array ?
Array.isArray('[11, 66]') return false since it's considered as string?
A good way to do this would be JSON.parse.
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.
In your example:
JSON.parse('[11, 66]')
Output:
[11, 66]
If the string is a valid JSON string, then use JSON.parse:
var array = JSON.parse(str);
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