jskatas.org Continuously Learn JavaScript. Your Way.

Destructuring: array

Destructuring arrays allows for more concise.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Destructuring arrays makes shorter code

  • extract value from array, e.g. extract 0 into x like so let [x] = [0];
  • get the last item from array
  • swap two variables, in one operation
  • leading commas
  • extract from nested arrays
  • chained assignments
  • in for-of loop