JavaScriptのオブジェクトの配列から重複を削除する
1242 ワード
JavaScriptのオブジェクトの配列から重複を削除する
Sep 24 ' 20
5
const things = [
{place:"here",name:"stuff"},
{place:"there",name:"morestuff"},
{place:"there",name:"morestuff"}
];
const filteredArr = things.reduce((thing, current) => {
const x = thing.find(item => item.place === current.place);
if (!x) {
return thing.concat([current]);
} else {
return thing;
}
}, []);
console.log(filteredArr)
Open Full Answer
Reference
この問題について(JavaScriptのオブジェクトの配列から重複を削除する), 我々は、より多くの情報をここで見つけました
https://dev.to/abdullahalnoor/answer-remove-duplicates-from-an-array-of-objects-in-javascript-4811
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
const things = [
{place:"here",name:"stuff"},
{place:"there",name:"morestuff"},
{place:"there",name:"morestuff"}
];
const filteredArr = things.reduce((thing, current) => {
const x = thing.find(item => item.place === current.place);
if (!x) {
return thing.concat([current]);
} else {
return thing;
}
}, []);
console.log(filteredArr)
Reference
この問題について(JavaScriptのオブジェクトの配列から重複を削除する), 我々は、より多くの情報をここで見つけました https://dev.to/abdullahalnoor/answer-remove-duplicates-from-an-array-of-objects-in-javascript-4811テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol