Answers for "destructure array of objects javascript"

0

js Destructuring arrays and objects

// 1) Destructure array items
const [first, second,, fourth] = [10, 20, 30, 40];

// 2) Destructure object properties
const { PI, E, SQRT2 } = Math;
Posted by: Guest on March-07-2022
0

Destructuring of array in ES6

function printFirstAndSecondElement([first, second]) {
    console.log('First element is ' + first + ', second is ' + second)
}

function printSecondAndFourthElement([, second, , fourth]) {
    console.log('Second element is ' + second + ', fourth is ' + fourth)
}

var array = [1, 2, 3, 4, 5]

printFirstAndSecondElement(array)
printSecondAndFourthElement(array)
Posted by: Guest on April-10-2022
0

js The equivalent of destructuring arrays and objects

// 1) assuming arr is [10, 20, 30, 40]
const first = arr[0];
const second = arr[1];
// third element skipped
const fourth = arr[3];

// 2)
const PI = Math.PI;
const E = Math.E;
const SQRT2 = Math.SQRT2;
Posted by: Guest on March-08-2022

Code answers related to "destructure array of objects javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language