Click here to Skip to main content
14,829,031 members
Please Sign up or sign in to vote.
1.12/5 (5 votes)
See more:
var a="a,s,d,f";
var b="5,6,7,8";
var c = new array();

i need to use that string and create an array
c=[["a",5],["s",6],["d",7],["f",8]]
Posted
Comments
F-ES Sitecore 10-Dec-15 7:10am
   
Use split to turn each string into an array

http://www.w3schools.com/jsref/jsref_split.asp

Then make a multi-dimensional array from those

http://www.w3schools.com/js/js_arrays.asp
phil.o 10-Dec-15 7:22am
   
This would deserve to be posted as a solution on its own :)
Sergey Alexandrovich Kryukov 10-Dec-15 10:03am
   
It all sounds quite trivial, but you did not really explain what exactly you want to do. An example is not specification. Is the delimiter always ','? What to do if the number of "list elements" are different? numbers are without quotation, so what if some elements are not numbers? And first of all, why all that? You have to parse strings, but how did you end up with those strings in first place? Maybe you should have done something else.
—SA
Member 10902837 11-Dec-15 9:58am
   
i Have a pie chart to show the data for that i need a array in that format.
var A="a,b,c,d"; //this will be string or integer
var B = "1,2,3,4" ; this will be integer
var c = new array(); // ill have to get the above A,B in to this C

i want that in the format of

c= [["a",1],["b",2],["c",3],["d",4]];

can u give me function to do this array format

Thank you somuch

1 solution

var a="a,s,d,f".split(",");
var b="5,6,7,8".split(",");

var c = a.map(function (e, i) {
return [a[i], b[i]];
});
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900