“JavaScript Object Destructuring” Kode Jawaban

Objek Menghancurkan

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;
Scary Snail

Objek Menghancurkan

Object Destructuring =>
//
   The destructuring assignment syntax is a JavaScript expression that makes it
possible to unpack values from arrays,
or properties from objects, into distinct variables.
//
example:
const user = {
    id: 42,
    is_verified: true
};

const {id, is_verified} = user;

console.log(id); // 42
console.log(is_verified); // true 
kepl3r

Contoh Destrukturisasi Objek

const hero = {
  name: 'Batman',
  realName: 'Bruce Wayne',
  address: {
    city: 'Gotham'
  }
};

// Object destructuring:
const { realName, address: { city } } = hero;
city; // => 'Gotham'
Nutty Narwhal

JavaScript Object Destructing

const employee = {name: ‘ANE01’, email: ‘[email protected]’, phone:’0112–345–6789'};
//with destucturing
const {name, email, phone} = employee;
//without destucturing
const name = employee.name;
const email = employee.email;
const phone = employee.phone;
Cute Civet

JavaScript Destructuring

// before you would do something like this
const person = {
    name: 'Sara',
    age: 25,
    gender: 'female'    
}

let name = person.name;
let age = person.age;
let gender = person.gender;

console.log(name); // Sara
console.log(age); // 25
console.log(gender); // female
SAMER SAEID

JavaScript Object Destructuring

// In this syntax:

let { property1: variable1, property2: variable2 } = object;

// The identifier before the colon (:) is the property of the object and the identifier after the colon is the variable.
Oscar Gálvez

Jawaban yang mirip dengan “JavaScript Object Destructuring”

Pertanyaan yang mirip dengan “JavaScript Object Destructuring”

Lebih banyak jawaban terkait untuk “JavaScript Object Destructuring” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya