const simpleArr = ['find', 'the', 'bug', 'pls']
const doubleArr = [
['find', 'the', 'bug', 'pls'],
['we', 'solved', 'it', '🔥']
]
Simple Array Destructuring.
const [firstValue, secondValue] = simpleArr
console.log(firstValue) // find
console.log(secondValue) // the
Jump values & assign new value.
const [, , thirdValue = 'nope'] = simpleArr
console.log(thirdValue) //bug
Example with new value:
const simpleArr = ['find', 'the', undefined, 'pls']
const [, , newValue = 'nope'] = simpleArr
console.log(newValue) // nope
Get Nested arrays from a double array.
const [firstArray, secondArray] = doubleArr
console.log(firstArray) // [ 'find', 'the', 'bug', 'pls' ]
console.log(secondArray) // [ 'we', 'solved', 'it', '🔥' ]
Get values from nested arrays.
const [[, , third], [, second]] = doubleArr
console.log(third) // bug
console.log(second) // solved