“Menghancurkan dalam JavaScript” 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

merusak

var foo = ['one', 'two', 'three'];

// without destructuring
var one   = foo[0];
var two   = foo[1];
var three = foo[2];

// with destructuring
var [one, two, three] = foo;
Lovely Lion

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 dalam JavaScript

/*
Array Destructuring: The following example shows us how to convert all 
the elements of an array to a variable.

Object Destructuring: The following example shows us how to convert all 
the properties of an object into a variable.
*/
//Array Destructuring
const friends = ['Bill', 'Gates'];
const [firstName, secondName] = friends;
console.log(secondName);  //Gates

//Object Destructuring
const person = {name: "Bill Gates", age: 17, phone: "123456789"};
const {name} = person;
console.log(name);  //Bill Gates
Tiny Coders

Menghancurkan dalam JavaScript

const { name, age, job } = { name: 'abrar', age: 24, job: 'web-developer' }
console.log(name, age, job)
Ariful Islam Adil(Code Lover)

Jawaban yang mirip dengan “Menghancurkan dalam JavaScript”

Pertanyaan yang mirip dengan “Menghancurkan dalam JavaScript”

Lebih banyak jawaban terkait untuk “Menghancurkan dalam JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya