Is there a clever (i.e. optimized) way to rename a key in a javascript object?
A non-optimized way would be:
o[ new_key ] = o[ old_key ]; delete o[ o
You can try lodash _.mapKeys.
var user = { name: "Andrew", id: 25, reported: false }; var renamed = _.mapKeys(user, function(value, key) { return key + "_" + user.id; }); console.log(renamed);