Skip to content

Instantly share code, notes, and snippets.

@keidarcy
Last active April 21, 2020 05:34
Show Gist options
  • Save keidarcy/cfb6c8b7387f885d58120bb094fda086 to your computer and use it in GitHub Desktop.
Save keidarcy/cfb6c8b7387f885d58120bb094fda086 to your computer and use it in GitHub Desktop.
Some JavaScript memo
const obj = [
{ name: "Joe", age: 17 },
{ name: "Bob", age: 17 },
{ name: "Carl", age: 35 }
];
const objRes = [...new Map(obj.map((item) => [item.age, item])).values()];
const arrRes = [...new Set(obj.map((item) => item.age))]
console.log(objRes); //[{ name: "Bob", age: 17 },{ name: "Carl", age: 35 }]
console.log(arrRes);//[17, 35]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment