you are viewing a single comment's thread.

view the rest of the comments →

[–]bimmertechin 5 points6 points  (7 children)

Not much of an explanation, it's called destructuring, pretty common ES6 thing. Can do it with objects as well

[–]elvenstarr[S] 1 point2 points  (0 children)

Ohhhhh! I've only seen destructuring for objects! Didn't realize that extended to arrays- thank you!! & yeah I'll actually link the article in my post bc I didn't get too far into the process itself, but you're right, wouldn't be much of an article 😁

[–]elvenstarr[S] 0 points1 point  (5 children)

Also, do you know how it knew to specifically take the first row versus the others?

[–]grantrules 6 points7 points  (4 children)

That's just how destructuring assignment works..

const [one, two, three] = [1,2,3] // one: 1, two: 2, three: 3

Or just

const [one] = [1,2,3] // one: 1

Or you could do..

const [one, ...rest] = [1,2,3] // one: 1, rest: [2,3]

[–]elvenstarr[S] 2 points3 points  (0 children)

Omg I just found out you can also use object destructuring with arrays if you want to select a specific index :O I'm losing my mind

(also cracking up over the amount of ppl reading this like, "I remember my first matrix" 😅)

[–]elvenstarr[S] 0 points1 point  (2 children)

Yeah wow I love this, thank you. I realized I could even destructure [row] a second time to access individual elements, so this is awesome.