假设我有一个形状如此的物体:
{
rows: [
{some: fields,
go: here}]
}
,并且说,在特定情况下,我知道行的长度是1.我怎么能通过解构来提取{some:fields,go:here}?
我尝试过:{rows: [stuff]}
和{rows: stuff}
,但在这两种情况下console.log(stuff)
都会打印[{some: fields, go: here}]
如何通过解构来实现这一目标?
答案 0 :(得分:0)
{rows: [stuff]}
效果很好:
const obj = {
rows: [
{some: 'fields',
go: 'here'}]
};
const { rows: [stuff] } = obj;
console.log(stuff);