1

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(",");
2
  • I can see them as integer array only Commented Sep 4, 2018 at 9:25
  • is salesdata string? Commented Sep 4, 2018 at 9:27

3 Answers 3

4

You can use JSON.parse() to convert that string array to actual array type.

console.log(JSON.parse(salesdata))
Sign up to request clarification or add additional context in comments.

Comments

1

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));

Comments

1

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])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.