Last active
April 21, 2020 05:34
-
-
Save keidarcy/cfb6c8b7387f885d58120bb094fda086 to your computer and use it in GitHub Desktop.
Some JavaScript memo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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