0

I can't seem to find the answer for this but how can you access an individual array element by it's index number in jQuery's each method?

Stright JS would do it like this:

for(i=0; i<myArray.length; i++)
{
    if(i === 1)
    {    
        // do something
    }
}

But I can't seem to figure out how to use find the index number in the each method...?

myArray.each(function()
{
    if(this[1])
    {
        // doesn't work?
    }
}

Thank you for any help.

1 Answer 1

6

do:

$.each(myArray, function(index, value) {
    alert(index + ': ' + value);
});

And more importantly, see: jQuery.each()

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh, thank you. Sorry for such a simple question, but I've been working all night on some code and my brain is fried.
@Freethinker no prob... happens at times.. :)

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.