Sometimes, we want to convert string array representation back to an array with JavaScript.
In this article, we’ll look at how to convert string array representation back to an array with JavaScript.
How to convert string array representation back to an array with JavaScript?
To convert string array representation back to an array with JavaScript, we can use JSON.parse
.
For instance, we write:
const s = '["item1", "item2", "item3"]'
const a = JSON.parse(s)
console.log(a)
to call JSON.parse
with s
to convert s
back to an array.
Therefore, a
is ["item1", "item2", "item3"]
.
Conclusion
To convert string array representation back to an array with JavaScript, we can use JSON.parse
.