profileRyan KesPGP keyI build stuffEmailGithubTwitterLast.fmMastodonMatrix

Destructuring Arrays

Introduction

Destructuring arrays was introduced in ES6. Iterables can also be destructured via the same principle.

Syntax

const [, year, month, day] = /^(\d\d\d\d)-(\d\d)-(\d\d)$/.exec("2999-12-31")

console.log(`${year} ${month} ${day}`) // 2999 12 31

See also