snippets/old_snippets/destructure-array-javascript.en.md

605 B

title date draft seo_description snippet_types
destructuring an array in javascript 2021-11-29T09:22:30+01:00 false Turns out you don't need blank variables at all, simply using commas is enough
js

How I use to destructure Arrays:

const nums = [1,2,3];
const [a, _, c];
(a === 1) // true
(c === 3) // true

Problem is this _ is not needed and will cause problems with some ESLint setups. For example they might not allow unused variables. Turnes out you can just leave that spot blank!

const nums = [1,2,3];
const [a, , c];
(a === 1) // true
(c === 3) // true