I'm trying to destructure this object:
{
name: "Bryan",
last-name: "Enid"
}
and this is not possible:
const {name, last-name} = req.body
Is there a way to destructure this, without changing the initial object key name?
I'm trying to destructure this object:
{
name: "Bryan",
last-name: "Enid"
}
and this is not possible:
const {name, last-name} = req.body
Is there a way to destructure this, without changing the initial object key name?
You need to rename the variable, because minus is an operator and not part of a variable name.
BTW, name
is a property of Window.name
. if this is used you need to rename this value as well.
const { name, 'last-name': lastName } = { name: 'foo', 'last-name': 'bar' };
console.log(lastName);