sai pavan
sai pavan

Reputation: 37

How to destructure multiple values from the object?

I want to destructure the values from the same object inside multiple objects.

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

Is there any way to destructure in single line as floor1, floor2

Upvotes: 1

Views: 88

Answers (1)

rohit.bels
rohit.bels

Reputation: 94

As simple as that:

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

Upvotes: 5

Related Questions