Home > Software engineering >  How to destructor to get property message
How to destructor to get property message

Time:05-17

I like to have this complex object to be destructured so I can have the property "message".

How can I achieve this?

complex object to destructured

{"data":[{"success":false,"message":"Not Found!"}]}

CodePudding user response:

const { data: [{ message},]} = {"data":[{"success":false,"message":"Not Found!"}]}

console.log(message)

CodePudding user response:

const obj = {"data":[{"success":false,"message":"Not Found!"}]};

const {data: [{message}]} = obj;

console.log(message); // Not Found!
  • Related