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(",");
Death-is-the-real-truth
72.3k10 gold badges59 silver badges106 bronze badges
asked Sep 4, 2018 at 9:24
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))
answered Sep 4, 2018 at 9:31
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));

answered Sep 4, 2018 at 9:27

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])
answered Sep 4, 2018 at 9:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.