Reputation: 350
I have the following situation, what I want to know is how I go about creating the objects (since I have no idea how many there will be):
jQuery.each($itemList, function() {
<something> = new ItemObject(this[1], this[2]);
});
Can something be an array? If so, do I use .push? or is there a better way of doing this?
Upvotes: 1
Views: 47
Reputation: 236192
Its probably the most convinient way to push those newly created objects into an Array.
var objectList = [ ];
jQuery.each($itemList, function() {
objectList.push( new ItemObject(this[1], this[2]) );
});
// somewhere else
objectList.forEach(function( obj ) {
// do something great
});
Upvotes: 2