本文翻译自:Find object by id in an array of JavaScript objects
I've got an array: 我有一个数组:
myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
I'm unable to change the structure of the array. 我无法更改数组的结构。 I'm being passed an id of 45
, and I want to get 'bar'
for that object in the array. 我正在传递id为45
,并且我想为数组中的该对象获取'bar'
。
How do I do this in JavaScript or using jQuery? 如何在JavaScript或jQuery中做到这一点?
#1楼
参考: