“Menghancurkan di ES6” 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

Menghancurkan di ES6

let {a, b, c} = obj
Outrageous Ostrich

Menghancurkan di ES6

var a = obj.a
var b = obj.b
var c = obj.c
Outrageous Ostrich

Objek Menghancurkan dalam JavaScript

const hero = {
  name: 'Batman'
};
// Object destructuring:
const { name: heroName } = hero;
heroName; // => 'Batman'
Dangerous Dunlin

Jawaban yang mirip dengan “Menghancurkan di ES6”

Pertanyaan yang mirip dengan “Menghancurkan di ES6”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya