Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Destructure nested object properties

const item = {
  id: 1234,
  name: "sony wf1000xm3",
  category: {
  	mainCategory: "electronics,
    subCategory:'earphones'
  }
};

const {
  category: { subCategory },
} = item;

console.log(category);
// reference error

const {
  category: { subCategory },
  category,
} = item;

console.log(subcategory);
// earphones

console.log(category);
// {mainCategory: "electronics,subCategory:'earphones'}
		
Source by h.daily-dev-tips.com #
 
PREVIOUS NEXT
Tagged: #Destructure #nested #object #properties
ADD COMMENT
Topic
Name
8+3 =