Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  75] [ 6]  / answers: 1 / hits: 16709  / 12 Years ago, mon, february 11, 2013, 12:00:00

I have two arrays. How can I join them into one multidimensional array?



The first array is:



var arrayA = ['Jhon, kend, 12, 62626262662', 
'Lisa, Ann, 43, 672536452',
'Sophie, Lynn, 23, 636366363'];


My other array has the values:



var arrayB = ['Jhon', 'Lisa', 'Sophie']; 


How could I get an array with this format??



var jarray = [['Jhon', ['Jhon, kend, 12, 62626262662']], 
['Lisa', ['Lisa, Ann, 43, 672536452']],
['Sohphie', ['Sophie, Lynn, 23, 636366363']]]

More From » arrays

 Answers
184
var jarray = [];
for (var i=0; i<arrayA.length && i<arrayB.length; i++)
jarray[i] = [arrayB[i], [arrayA[i]]];


However, I wouldn't call that multidimensional array - that usually refers to arrays that include items of the same type. Also I'm not sure why you want the second part of your arrays be an one-element array.


[#80284] Sunday, February 10, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;