1

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?

3
  • 1
    What will you be using <something> for ? Commented Nov 28, 2011 at 11:21
  • 2
    Something can be an Array, it's probably the best way to do it. Commented Nov 28, 2011 at 11:21
  • Every object (something) refers to a picture on the webpage (there are an unknown amount of pictures on the page). Every 10 seconds I need to change attributes on all images. It is a bit complex to explain what and why because each image has it's own unique bahaviour depending on a number which is retrieved via PHP. Commented Nov 28, 2011 at 11:26

1 Answer 1

2

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
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I wasn't sure this was the best way of doing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.