js配列オブジェクトから属性値が等しいオブジェクトを取得します.

623 ワード

例:
var outArr=[
	{"name":"  ","id":1,age:18},
	{"name":"  ","id":2,age:19},
	{"name":"  ","id":3,age:18},
	{"name":"  ","id":4,age:20},
	{"name":"  ","id":5,age:17},
	{"name":"  ","id":6,age:18}
];
var newArr = outArr.filter(function (obj) {
    return obj.age== 18;
});
console.log(newArr);    // [{"name":"  ","id":1,age:18},{"name":"  ","id":3,age:18},{"name":"  ","id":6,age:18}]