Reputation: 14270
I need to create a array like the following
var new = 'New';
var old = 'Old';
var posterArray = [new, old];
//I want to push posterType and posterYear into new and old array
var posterType = [{'id':123, 'name':'test'}, {'id':456, 'name':'test'}];
var posterYear = [{'year':12345, 'status':'old'}, {'year': 3456, 'name':'old'}];
Is there anyway I can push posterType
and posterYear
into new
and old
variable inside the posterArray
? For example, posterArray[0].push(postertype)
. Basically I need mullti-dimentional array and I am not sure how to accomplish here. Thanks for the help!
Upvotes: 0
Views: 47
Reputation: 689
Seems like this would suffice your needs:
var posterArray = {
new: null,
old: null
};
Then later on:
posterArray.new = [{'id':123, 'name':'test'}, {'id':456, 'name':'test'}];
posterArray.old = [{'year':12345, 'status':'old'}, {'year': 3456, 'name':'old'}];
And you can even do:
var newObj = {
id: 234,
name: 'newtest'
};
posterArray.new.push(newObj);
EDIT Also heed ryanyuyu's warning: new
is a reserved keyword in javascript
Upvotes: 1