I have the following string
salesdata=[[0],[0],[0.767],[1.366],[2.003],[15.128],[32.766],[57.225],[0],[0],[0],[0]];
I want to convert it to an integer array with the same format of brackets to pass as highcharts input. I tried this
var data=salesdata.split(",");
Death-is-the-real-truth
72.3k10 gold badges59 silver badges106 bronze badges
3 Answers 3
You can use JSON.parse() to convert that string array to actual array type.
console.log(JSON.parse(salesdata))
answered Sep 4, 2018 at 9:31
Waleed Arshad
1,0993 gold badges12 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use eval() to convert that string array to actual array type. But note that eval() is highly discouraged to use in the code.
var salesdata=`[[0],[0],[0.767],[1.366],[2.003],[15.128],[32.766],[57.225],[0],[0],[0],[0]]`;
console.log(eval(salesdata));
answered Sep 4, 2018 at 9:27
Ankit Agarwal
30.8k5 gold badges41 silver badges63 bronze badges
Comments
Assuming your salesdata is of the below format:
var salesdata='[[0],[0],[0.767],[1.366],[2.003],[15.128],[32.766],[57.225],[0],[0],[0],[0]]';
You can convert it to integer using,
var salesdata_array = JSON.parse(salesdata); console.log(salesdata_array[0])
answered Sep 4, 2018 at 9:30
Muthukrishnan
2,1972 gold badges18 silver badges16 bronze badges
Comments
default
salesdatastring?