DEV Community

emertola
emertola

Posted on • Edited on

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

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay