Is there a way to destructure or clone an object
into another one, renaming it's keys in the process ?
Example :
let getUser = () => { return {first: "Radio", last: "Reve"} }
let {first: firstName, last: lastName} = getUser()
let o = {firstName: firstName, lastName: lastName} // This is the line I don't wanna have to write
Is there an easy way to have the result stored in an object instead of two distinct variables, firstName
and lastName
?
I receive an object from the server with 10 keys, and I would like to pick only 2 keys, and rename those keys, with no extra libraries nor using a special function in a native a consistent way.