How to extract nested object property using array destructuring?

Karim Ali

I get undefined using this code:

const json = {"records":[{"recordid":"1694119","recordindex":1,"status":"updated successfully"}],"message":{"returncode":1}};

const { records: {status} } = json;             
console.log(status); 

How to get the expected: "updated successfully"?

trincot

Since records is an array, you need to add brackets:

const json = {"records":[{"recordid":"1694119","recordindex":1,"status":"updated successfully"}],"message":{"returncode":1}};

const { records: [{status}] } = json;             
console.log(status); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Omit property variable when using object destructuring

object destructuring: how to use intermediate nested property

Object property assignment with destructuring?

destructuring assignment of array stored in object property

Nested object and array destructuring

Nested Object destructuring

how does destructuring array get length property

How to handle nested default parameters with object destructuring?

Nested object destructuring and renaming

How to extract value of nested object array?

How to extract property of array in nested array

Destructuring Nested Object

Extract nested JSON array response object using JS Lodash in Postman

Nested object destructuring with computed object property names - react state

ES6 destructuring get nested object property

how to filter array object using object property

How can I add array values to an object using destructuring?

Destructuring an object with "delete" as property

Nested in object array destructuring with assignment

How to extract an array from an object with property and array in typescript?

How to use array destructuring and assign to an object property in JavaScript ES6

How to simplify using array destructuring

Extract nested property from array

Destructuring a Object nested inside Array

How to override object destructuring for ES class just like array destructuring

How to object property parse to nested array array using javascript?

destructuring nested level of array of object

How to loop through nested array of objects and add a new property to each object in array using javascript

How to update a property of object in a nested array in MongoDB?