Reputation: 22147
How to push array in array via using Javascript ?
I know only push normal array like...
var arr = [];
arr.push(['one','two','three']);
That is..
array(
'one',
'two',
'three'
)
But what about ? How to push like this...
array(
array(
'one',
'one_two'
),
'two',
'three'
)
Upvotes: 0
Views: 343
Reputation: 3011
You can also use
var oldArray = new Array() // Put something inside
var newArray = {a:valueA, b:valueB, c:valueC}
oldArray.push(newArray)
Best
Upvotes: 0
Reputation: 700182
That's what you are doing already.
This code makes a single array:
var arr = [];
arr.push('one','two','three'); // push three items
I.e. the same result as:
var arr = ['one','two','three'];
This code makes a jagged array (an array in an array):
var arr = [];
arr.push(['one','two','three']); // push one item that is an array
I.e. the same result as:
var arr = [
['one','two','three']
];
Upvotes: 2