array destructuring methods parameters code example

Example 1: array destructuring methods parameters

const items = [ ['foo', 3], ['bar', 9] ];
items.forEach(([word, count]) => {
    console.log(word+' '+count);
});

Example 2: array destructuring methods parameters

function foo([a, b]) {
   console.log(`param1: ${a}, param2: ${b}`);
}

Example 3: array destructuring in javascript

const array = ['ismail', 'sulman'];
// array destructuring
const [firstElement, secondElement] = array;
console.log(firstElement, secondElement);
const secondArray = ['ismail', 'naeem', 'Mr', 1];
const [firstEl, secondEl, ...array1] = secondArray;
console.log(firstEl, secondEl, array1);