简体   繁体   English

如何从 object 中解构多个值?

[英]How to destructure multiple values from the object?

I want to destructure the values from the same object inside multiple objects.我想从多个对象内的同一个 object 中解构这些值。

const data ={
  building1: {
    floor: 'cnt',
  }
  building2: {
    floor: 'bcnt'
  }
}

Is there any way to destructure in single line as floor1, floor2有没有办法在单行中解构为floor1, floor2

As simple as that:就如此容易:

const { building1: { floor: floor1 },building2: { floor: floor2 }} = data;

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

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