Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a array Arr_All
Again i have 3 more array Arr1,Arr2,Arr3
i want to addd Arr1,Arr2,Arr3 to Arr_All
Like Arr_All[0] = Arr1;
Arr_All[0] = Arr2;
Arr_All[0] = Arr3;
Any suggestions Plz!
Posted
Updated 5-Feb-13 1:59am
v2

It depends on weather you want to add the items from Arr1, Arr2 and Arr3 or add the actuall arrays.

For example, this solution adds the items;

JavaScript
function add(source, target) {
    for(var i = 0; i < source.length; ++i)
        target.push(source[i]);
}

var Arr_all = [];
var Arr1 = [1, 2, 3];
var Arr2 = [4, 5, 6];
var Arr3 = [7, 8, 9];

add(Arr1, Arr_all);
add(Arr2, Arr_all);
add(Arr3, Arr_all);


This leaves the content of Arr_all as;
[1, 2, 3, 4, 5, 6, 7, 8, 9]

But if you want to add the actual arrays you'd do;

JavaScript
var Arr1 = [1, 2, 3];
var Arr2 = [4, 5, 6];
var Arr3 = [7, 8, 9];

var Arr_all = [Arr1, Arr2, Arr3];


That leaves the content of Mcode>Arr_all as;
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]

Hope this helps,
Fredrik
 
Share this answer
 
Comments
Ankur\m/ 5-Feb-13 8:32am    
That was explained much better! :thumbsup:
Fredrik Bornander 5-Feb-13 8:42am    
Thanks :)
In JavaScript, it's pretty simple!
JavaScript
var Arr1 = new Array(1, 2, 3);
var Arr2 = new Array(4, 5);
var Arr3 = new Array(7, 8, 9, 10);
var Arr_All = new Array(Arr1, Arr2, Arr3);

You can access it similar to how you access multidimensional array in C#
You may need JavaScript array properties and methos[^] to access the contents dynamically.

Hope this helps!
 
Share this answer
 
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