const filterUnique = () => { const keys = new Set(); return (key) => !keys.has(key) ? keys.add(key) || true : false; }; const filterById = filterUnique(); console.log([{ id: 1 },{ id: 2 },{ id: 3 },{ id: 2 }].filter(x => filterById(x.id)));
391800cookie-checkJavascript filter unique / duplicates closure