Filter
array of objects, which property matches value, returns array:
(Filter
对象数组,其属性与值匹配,返回数组:)
var result = jsObjects.filter(obj => {
return obj.b === 6
})
See the MDN Docs on Array.prototype.filter()
(请参阅Array.prototype.filter()上的MDN文档)
const jsObjects = [ {a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8} ] let result = jsObjects.filter(obj => { return obj.b === 6 }) console.log(result)
Find
the value of the first element/object in the array, otherwise undefined
is returned.
(Find
数组中第一个元素/对象的值,否则返回undefined
。)
var result = jsObjects.find(obj => {
return obj.b === 6
})
See the MDN Docs on Array.prototype.find()
(请参阅Array.prototype.find()上的MDN文档)
const jsObjects = [ {a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8} ] let result = jsObjects.find(obj => { return obj.b === 6 }) console.log(result)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…