Skip to content

Instantly share code, notes, and snippets.

@nesk
Created March 16, 2018 14:40
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 nesk/169b30b70c3e8b5ab32b5c751fa2fa08 to your computer and use it in GitHub Desktop.
Save nesk/169b30b70c3e8b5ab32b5c751fa2fa08 to your computer and use it in GitHub Desktop.
Mapping objects in JavaScript (ES2017+)
const data = {
a: 1,
b: 2,
};
const newData = Object.entries(data)
.map(([key, value]) => ({ [`_${key}`]: value + 1 }))
.reduce((obj, item) => Object.assign(obj, item), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment