One of the most interesting features that ES6 added to JavaScript was object and array destructuring. With destructuring we can take part of an array or an object very easily. Let’s understand by taking up a few examples

Array Destructuring

const alphabets = ['A','B','C','D','E','F']
const numbers = ['1','2','3','4','5','6']

Now if we have to pick the first two items from the alphabets array. The conventional way would be,

const a = alphabets[0]
const b = alphabets[1]
console.log(a)
//expected output : A
console.log(b)
//expected output : B

It is very obvious that the above approach is very clunky and there is a much easier…

Vikash Kumar Jha

Full Stack Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store