按价值或财产获得对象的数组JavaScript对象 [英] Get JavaScript object from array of objects by value or property
本文介绍了按价值或财产获得对象的数组JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有四个对象的数组:
VAR jsObjects = [
{A:1,B:2},
{A:3,B:4},
{A:5,B:6},
{一:7,B:8}
];
有没有一种方法,我可以得到第三个对象( {A:5,B:6}
)的属性值 b
例如无为中...
循环?
解决方案
VAR的结果= jsObjects.filter(函数(OBJ){
返回obj.b == 6;
});
查看<一个href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\">MDN在Array.prototype.filter文档()
Let's say I have an array of four objects:
var jsObjects = [
{a: 1, b: 2},
{a: 3, b: 4},
{a: 5, b: 6},
{a: 7, b: 8}
];
Is there a way that I can get the third object ({a: 5, b: 6}
) by the value of the property b
for example without a for...in
loop?
解决方案
var result = jsObjects.filter(function( obj ) {
return obj.b == 6;
});
See the MDN Docs on Array.prototype.filter()
这篇关于按价值或财产获得对象的数组JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文