I have an array:
var array = ['1,2,3']
How do i remove the: ' from that array so i get the output [1,2,3]
I have tried doing the .replace replace("\''", "") but still get the same output.
I have an array:
var array = ['1,2,3']
How do i remove the: ' from that array so i get the output [1,2,3]
I have tried doing the .replace replace("\''", "") but still get the same output.
You can use map
on array and then split
on value.
var array = ['1,2,3']
array = [].concat(...array.map(e => e.split(',').map(Number)))
console.log(array)
For the specific case you’ve given, with just one string item in the array, it can be boiled down to:
var array = ['1,2,3']
var result = array[0].split(',').map(x => +x)
// ^ ^ ^ ^^^^ ^
// 1 2 3 4 5
console.log(result)
If you might have many string items in your array, like:
var array = [‘1,2,3’, ‘4,5,6’]
then Nenad’s answer’s great.