1

I need to split the data in the array , the sample data is as the following .

 var data = [1, "Asia,11,3,0,27.0,0.0"];

How to split this into two values

2

2 Answers 2

0

Maybe you mean this:

var data = [1, "Asia,11,3,0,27.0,0.0"];
var first = data[0]; // 1
var second = data[1]; // "Asia,11,3,0,27.0,0.0"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, your solution is apt for my requirement
0

It's quite easy with Array methods. For example, you can expand your array like this:

data.splice.apply(data, [1, 1].concat(data[1].split(',')));

And there is a demo:

var data = [1, "Asia,11,3,0,27.0,0.0"];

data.splice.apply(data, [1, 1].concat(data[1].split(',')));

// print result
document.write('<pre>' + JSON.stringify( data, null, 4 ) + '</pre>');

Check useful Array.prototype methods:

and String.prototype.split method.

Comments

Your Answer

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.