Created
June 18, 2020 00:36
-
-
Save godmar/f7012d3f05c86a3c8ad76e35afa9bbf7 to your computer and use it in GitHub Desktop.
output is:
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
countries = [ | |
{ country: "US", rank: 3 }, | |
{ country: "US", rank: 4 }, | |
{ country: "UK", rank: 3 }, | |
{ country: "UK", rank: 3 }, | |
{ country: "Germany", rank: 7 }, | |
]; | |
let o1 = Object.fromEntries(countries.map(c => [c.country, 1])); | |
console.log(o1); | |
let a1 = Object.keys(o1); | |
console.log(a1); | |
let o2 = a1.map(country => ({ country: country })); // the () around { } are important | |
console.log(o2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output is