简体   繁体   English

使用jQuery each()访问单个数组元素

[英]Accessing individual array elements using jQuery each()

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? 我似乎找不到答案,但是如何在jQuery的each方法中按索引号访问单个数组元素?

Stright JS would do it like this: Stright JS会这样做:

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. 感谢您的任何帮助。

do: 做:

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

And more importantly, see: jQuery.each() 更重要的是,请参见: jQuery.each()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM