data={data.map(({ ID,filePath,accountId,companyId,['First Name'], ...rest }) => rest)}在这种情况下,名字是带空格的键,显然,当按上面传递时,它会导致错误。如何处理这种情况?
发布于 2019-12-19 07:50:14
变量名称(标识符)不能在其中包含空格,除非还可以重命名变量,否则您将无法将该属性分解为独立的变量--这可以使用括号符号来完成:
data.map(({
ID,
filePath,
accountId,
companyId,
['First Name']: firstName,
...rest
}) => rest)
const data = [
{
'First Name': 'foo',
'anotherProp': 'another'
},
{
'First Name': 'bar',
'anotherProp': 'another'
}
];
const mapped = data.map(({
ID,
filePath,
accountId,
companyId,
['First Name']: firstName,
...rest
}) => rest);
console.log(mapped);
https://stackoverflow.com/questions/59405314
复制相似问题