l2aelba
l2aelba

Reputation: 22147

Push Array in Array

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

Answers (3)

xhallix
xhallix

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

Guffa
Guffa

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

Vinay
Vinay

Reputation: 6881

like this.

arr.push([['one','two','three']]);

Upvotes: 2

Related Questions