js destructuring objects code example
Example 1: javascript function destructuring
function f() {
return [1, 2];
}
let a, b;
[a, b] = f();
console.log(a); // 1
console.log(b); // 2
Example 2: 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);