javascript destructuring spred operatorobject code example
Example 1: object destructuring
const book = {
title: 'Ego is the Enemy',
author: 'Ryan Holiday',
publisher: {
name: 'Penguin',
type: 'private'
}
};
const {title: bookName = 'Ego', author, name: {publisher: { name }} = book, type: {publisher: { type }} = book } = book;
Example 2: destructuring Object in JavaScript
let {name, country, job} = {name: "Sarah", country: "Nigeria", job: "Developer"};
console.log(name);
console.log(country);
console.log(job);