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

27 lines
605 B
Markdown

---
title: "destructuring an array in javascript"
date: 2021-11-29T09:22:30+01:00
draft: false
seo_description: "Turns out you don't need blank variables at all, simply using commas is enough"
snippet_types:
- js
---
How I use to destructure Arrays:
```js
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!
```js
const nums = [1,2,3];
const [a, , c];
(a === 1) // true
(c === 3) // true
```