简体   繁体   中英

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?

You can use computed property name

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

标识符不能包含连字符,因此您必须将属性重命名为有效的标识符名称:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM