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