Answers for "js array destructuring"

8

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;
Posted by: Guest on March-18-2020
1

Javascript array destructuring

let [a, b] = [9, 5]
[b, a] = [a, b]
console.log(a, b);
//Expected output: 5,9
Posted by: Guest on September-11-2021
1

destructuring Array in JavaScript

let [greeting = "hi",name = "Sarah"] = ["hello"];

console.log(greeting);//"Hello"
console.log(name);//"Sarah"
Posted by: Guest on May-25-2021
8

destructuring javascript

// destructuring array & nested array & combine array into single array
let person = ["John", "Sandy", "Sam", ["Mike", "Max"], "Diego", "Paul"];
// empty comma is like skipping array index. I skipped "Sam"
const [a, b, , c, ...d] = person;

let friend = [d, "Tom", "Jerry"] 
let newFriend = [...d, "Tom", "Jerry"]

console.log(a); // output: "John"
console.log(b); // output: "Sandy"
console.log(c); // output: [ "Mike", "Max" ]
console.log(d); // output: ["Diego", "Paul"]
console.log(friend); // output: [ [ 'Diego', 'Paul' ], 'Tom', 'Jerry' ]
console.log(newFriend); // output: [ 'Diego', 'Paul', 'Tom', 'Jerry' ]
Posted by: Guest on September-07-2021
0

mdn destructuring

const x = [1, 2, 3, 4, 5];
const [y, z] = x;
console.log(y); // 1
console.log(z); // 2
Posted by: Guest on November-07-2020
0

javascript destructing

/*
* On the left-hand side, you decide which values to unpack from the right-hand
* side source variable.
* 
* This was introduced in ES6
*/
const x = [1, 2, 3, 4, 5]
const [a, b] = x
console.log(a) // prints out: 1
console.log(b) // prints out: 2
Posted by: Guest on January-22-2021

Code answers related to "Objective-C"

Browse Popular Code Answers by Language