简体   繁体   中英

Spread array destructuring in react-native errored

The following code:

const [ ...routes, currentRoute ] = props.routes

Produces an unexpected token error on such line.

Why is this?

You can use rest operator only at the end of the destructuring expression, eg:

const [ currentRoute, ...routes ] = props.routes.reverse()

It is stated in ECMAScript 2015 Spec.#Destructuring Assignment , it could be hard to read but look at ArrayAssignmentPattern structure.

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