Reputation: 36846
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
Upvotes: 0
Views: 71
Reputation: 36574
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)
Upvotes: 1