Created
October 23, 2019 07:59
-
-
Save pooyagolchian/9683f5d90a45149ac6b54f58b3c12c80 to your computer and use it in GitHub Desktop.
Renaming Objects key
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
renameKeys = (keysMap, obj) => { | |
return Object.keys(obj).reduce((acc, key) => { | |
const renamedObject = { | |
[keysMap[key] || key]: obj[key] | |
}; | |
return { | |
...acc, | |
...renamedObject | |
}; | |
}, {}); | |
}; | |
renameKeys({ | |
name: 'Hamid', | |
job: 'Backend', | |
'a':'hamid', | |
'b':'reza' | |
}, { | |
name_2: 'Pooya', | |
job_2: 'Frontend' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment