1・名前の重複を削除したい
2・名前が重複していた場合、moneyが2000のデータだけ欲しい
process.stdin.resume();
process.stdin.setEncoding('utf8');
var arr = [
{id:1,name:"花子",money:5000},
{id:2,name:"江藤",money:4000},
{id:3,name:"山田",money:3000},
{id:4,name:"山田",money:2000},
{id:5,name:"山田",money:8888},
{id:6,name:"山田",money:9999},
{id:7,name:"松井",money:2000},
{id:8,name:"松井",money:2093},
{id:9,name:"松井",money:2090},
{id:10,name:"大川",money:1000}
];
var check = [];
arr.forEach(function(list) {
check[list.name] = (list.name in check) ? true : false;
});
var filtered = arr.filter(function (e) {
return false === check[ e.name ] || true === check[ e.name ] && e.money === 2000;
} );
console.log( filtered );
#結果
[
{ id: 1, name: '花子', money: 5000 },
{ id: 2, name: '江藤', money: 4000 },
{ id: 4, name: '山田', money: 2000 },
{ id: 7, name: '松井', money: 2000 },
{ id: 10, name: '大川', money: 1000 }
]