Search code examples
ecmascript-6destructuring

Nested es6 array destructuring?


Is it possible to nest destructuring?

E.g. I want the first item in an array and in that array I want the first item of that child array.

Given:

let arr = [['foo'], ['bar']];

Is there an easier way to do:

let firstItem = arr[0][0];

Solution

  • Ah figured this out:

    let [[firstItem]] = arr;
    

    That would be the equivalent.