how to destructure array of objects code example
Example 1: destructure array javascript
var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
Example 2: array destructuring
const myArray = ["a", "b", "c"];
const x = myArray[0];
const y = myArray[1];
console.log(x, y);
const myArray = ["a", "b", "c"];
const [x, y] = myArray;
console.log(x, y);
Example 3: destructured object
let renseignement = ['voleur' , '10' , 'spécialité'] ;
let [classe , force, magie] = renseignement ;
console.log(classe) ;
console.log(force) ;
console.log(magie) ;
Example 4: destructuring Array in JavaScript
function getArray() {
return ["Hello", "I" , "am", "Sarah"];
}
let [greeting,pronoun] = getArray();
console.log(greeting);
console.log(pronoun);
Example 5: destructuring Array in JavaScript
let a = 3;
let b = 6;
[a,b] = [b,a];
console.log(a);
console.log(b);