rob.m
rob.m

Reputation: 10571

Uncaught SyntaxError: Unexpected token -

I use

let op = data.map(({usp-custom-90})=> usp-custom-90 )

but that gives

Uncaught SyntaxError: Unexpected token -

I tried to replace dash with – but then I get errors in regards of &

How do I fix it?

Upvotes: 1

Views: 662

Answers (2)

Paul
Paul

Reputation: 141829

Identifiers cannot contain hyphens, so you must rename the property to a valid identifier name:

let op = data.map( ({ ['usp-custom-90']: uspCustom90 }) => uspCustom90 )

Upvotes: 3

guest271314
guest271314

Reputation: 1

You can use computed property name

let prop = `usp-custom-90`
let op = data.map(({[prop]:p})=> p)

Upvotes: 3

Related Questions