This might be a dumb question but I have a string like so:
"[1, 2, 3, 4]"
I want to convert it into an actual array:
[1, 2, 3, 4]
How do I go about this?
This might be a dumb question but I have a string like so:
"[1, 2, 3, 4]"
I want to convert it into an actual array:
[1, 2, 3, 4]
How do I go about this?
You should use AND validate Tom Finney's or Ashishya11's or Hasee Amarathunga's answer because mine contains a gross security vulnerability if your string input comes from an untrusted source. But anyways, you can also do it like this:
const array = eval('[1, 2, 3, 4]')