Random Front-end codes I learned today (#001) - Array destructure
emertola

emertola @emertola

About: Self-taught front-end developer

Location:
Manila, Philippines
Joined:
Sep 28, 2019

Random Front-end codes I learned today (#001) - Array destructure

Publish Date: Jan 23 '21
0 0

Without further intro, I'll go straight to the point.

What is Array destructure?

As MDN describes it, destructuring is a way of unpacking values from, in our case, an Array (or properties from an Object, but we'll focus on the Array on this topic).

There are a lot times, when I want to access a value from an array, say the first value, and store it in a variable, this is what I normally do:
Alt Text

With array destructuring, I discovered that I can do that in just a single line of code.
Alt Text

This means that the first value of the array (which is pencil) will immediately be stored to a variable pencil. It could also be another variable name, and it'll still be of the same result:
Alt Text

Comments 0 total

    Add comment