indexOf method in an object array?

前端 未结 27 2950
别跟我提以往
别跟我提以往 2020-11-22 02:18

What\'s the best method to get the index of an array which contains objects?

Imagine this scenario:

var hello = {
    hello: \'world\',
    foo: \'ba         


        
27条回答
  •  天涯浪人
    2020-11-22 02:45

    See this example: http://jsfiddle.net/89C54/

    for (i = 0; i < myArray.length; i++) {
        if (myArray[i].hello === 'stevie') {
            alert('position: ' + i);
            return;
        }
    }
    

    It starts to count with zero.

提交回复
热议问题