5
data={data.map(({ ID,filePath,accountId,companyId,['First Name'], ...rest }) => rest)}

In this case First Name is a key with space, apparently when passed as above it causes error. How to handle this scenario?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Joji Thomas
  • 73
  • 1
  • 3

1 Answers1

19

Variable names (identifiers) can't have spaces in them, you won't be able to destructure that property into a standalone variable unless you also rename the variable - which can be done using bracket notation:

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);
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320