I have an object:
let obj = { rows: [1, 2] }
How can I do ES6 array destructuring with assignment for value 1
?
For the array itself I can do like that, but I don't know how to get the first value:
let {rows: [first] } = obj
first // 1
Sorry, all is working in my example, was confused by error in my console.log test
If you want to get first value of array then use the code below.
const data ={ rows:[1,2,3] } let {rows:[first]} = data; console.log(first)
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.