Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Created March 23, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinpokorny/8a3c40a926c64392cf85e752887916cb to your computer and use it in GitHub Desktop.
Save robinpokorny/8a3c40a926c64392cf85e752887916cb to your computer and use it in GitHub Desktop.
Transform a list of entries with names (ids) to name-indexed Map
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