I have an array like this:
(我有一个像这样的数组:)
[{prop1:"abc",prop2:"qwe"},{prop1:"bnmb",prop2:"yutu"},{prop1:"zxvz",prop2:"qwrq"},...]
How can I get the index of the object that matches a condition, without iterating over the entire array?
(如何在不迭代整个数组的情况下获取与条件匹配的对象的索引?)
For instance, given prop2=="yutu"
, I want to get index 1
.
(例如,给定prop2=="yutu"
,我想获取索引1
。)
I saw .indexOf()
but think it's used for simple arrays like ["a1","a2",...]
.
(我看到了.indexOf()
但认为它用于简单的数组,例如["a1","a2",...]
。)
I also checked $.grep()
but this returns objects, not the index.(我还检查了$.grep()
但这返回对象,而不是索引。)
ask by amp translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…