loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const taxPayer = [ 'Ian', 'DesJardins', '123-45-6789', true ];

console.log('Array destructuring example');
// destructure the taxPayer array into new variables
const [ firstName, lastName, ssn, pastDue ] = taxPayer;
console.log('firstName =', firstName);
console.log('lastName =', lastName);
console.log('ssn =', ssn);
console.log('pastDue =', pastDue, '\n');

// may also be used to destructure an array for a function's parameter
function parseTaxPayerArray([firstName, lastName, ssn, pastDue]) {
    console.log('inside parseTaxPayerArray()');
    console.log('firstName =', firstName);
    console.log('lastName =', lastName);
    console.log('ssn =', ssn);
    console.log('pastDue =', pastDue);
}

parseTaxPayerArray(taxPayer);


console.log('\narray index access example')
// this is the equivalent of destructuring
const firstNameAgain = taxPayer[0];
const lastNameAgain = taxPayer[1];
const ssnAgain = taxPayer[2];
const pastDueAgain = taxPayer[3];
console.log('firstNameAgain =', firstNameAgain);
console.log('lastNameAgain =', lastNameAgain);
console.log('ssnAgain =', ssnAgain);
console.log('pastDueAgain =', pastDueAgain, '\n');