Answers for "destructure array of objects"

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 an array

let cars = ['ferrari', 'tesla', 'cadillac'];
let [car1, car2, car3] = cars;
console.log(car1, car2, car3); // Prints: ferrari tesla cadillac
Posted by: Guest on May-02-2022
0

Destructuring of object in ES6

function printBasicInfo({firstName, secondName, profession}) {
	console.log(firstName + ' ' + secondName + ' - ' + profession)
}

var person = {
  firstName: 'John',
  secondName: 'Smith',
  age: 33,
  children: 3,
  profession: 'teacher'
}

printBasicInfo(person)
Posted by: Guest on April-10-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"

Code answers related to "Javascript"

Browse Popular Code Answers by Language