0

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

Naor Talmor
  • 244
  • 2
  • 10
  • [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) will help you – Code Maniac Apr 16 '19 at 10:53

1 Answers1

0

Use JSON.parse() on your field:

const data = {
   filter: "[1,2,3]"
}

data.filter = JSON.parse(data.filter);

console.log(data);
jo_va
  • 13,504
  • 3
  • 23
  • 47
  • 1
    yes it works that way tnx; but strange thing, if you do the same thing just with array of strings insteaf of numbers it doesnt work ... – Naor Talmor Apr 16 '19 at 11:11