I'm getting and object from an api that looks like this -
data = {
...
filter: "[1,2,3]"
...
}
Now, i want to take that string of array and convert it to array of numbers, that is [1,2,3].
Thanks a lot
I'm getting and object from an api that looks like this -
data = {
...
filter: "[1,2,3]"
...
}
Now, i want to take that string of array and convert it to array of numbers, that is [1,2,3].
Thanks a lot
Use JSON.parse() on your field:
const data = {
filter: "[1,2,3]"
}
data.filter = JSON.parse(data.filter);
console.log(data);