简体   繁体   English

嵌套在带有分配的对象数组解构中

[英]Nested in object array destructuring with assignment

I have an object: 我有一个对象:

let obj = { rows: [1, 2] }

How can I do ES6 array destructuring with assignment for value 1 ? 如何为ES6数组分配值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 抱歉,在我的示例中一切正常,在console.log测试中被错误弄糊涂了

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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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