Created
March 23, 2017 10:42
-
-
Save robinpokorny/8a3c40a926c64392cf85e752887916cb to your computer and use it in GitHub Desktop.
Transform a list of entries with names (ids) to name-indexed Map
This file contains hidden or 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 iconList = [ | |
{ name: 'star', code: 7807, size: 20 /* ... */ }, | |
{ name: 'heart', code: 7897, size: 10 /* ... */ }, | |
{ name: 'arrow', code: 7822, size: 25 /* ... */ }, | |
{ name: 'home', code: 7901, size: 20 /* ... */ } | |
] | |
const entries = iconList.map(({ name, ...rest }) => [ name, rest ]) | |
const icons = new Map(entries) | |
console.log([...icons.keys()]) | |
// -> ["star", "heart", "arrow", "home"] | |
console.log(icons.get('star')) | |
// -> { code: 7807, size: 20, ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment