🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

JavaScript Object Destructuring

↗ Quelle (dev.to)
🗣️ Stimme:

Destructuring Objects



Like destructuring arrays, destructuring objects helps you and makes your code cleaner and better, but it’s different from destructuring arrays, here is how to do it:




  • First, for the whole explanation we will need this object, I used a sponge bob analogy for the object 🧽😁, so take a look at it and analyze it a little bit:




CODE
let heightInCm = 4;
const obj = {
personName: 'spongeBob',
personAge: 37,
personAddress: '124 Conch Street, Bikini Bottom, Pacific Ocean',
heightInCm: 10,
personHobbies: [
'Jellyfishing',
'Cooking Krabby Patties',
'Blowing Bubbles',
'Karate',
],
home: {
type: 'pineapple',
location: 'bikini bottom',
details: {
rooms: 3,
uniqueFeature: "it's underwater and shaped like a pineapple!",
},
},
};








  • now, let’s destruct two properties from the object:




CODE
const { personName, personAge } = obj;
console.log(personName, personAge); // spongeBob 37







  • as you saw, to destruct an object you have to use {curly braces}, then inside it, write variable names that are exactly the same as the property names we want to retrieve in the object.



*You can also make variable names different from the property names, just right the new variable name after a colon:




CODE
const { personName: name, personAge: age } = obj;
console.log(name, age); // spongeBob 37







  • as you can see, we changed personName to name & personAge to age.



*Default Values:




  • we can also set default values, in case when we try to access a property that does not exist in the object, example:




CODE
const { DriversLicense = ['no'] } = obj;
console.log(DriversLicense); // ['no']
// DriversLicense does not exist in obj, so the default value will be used.






* Mutating Variables while Destructuring Objects:




CODE
({ heightInCm } = obj);
console.log(heightInCm); // 10








  • in this example, if you look back you will find out that heightInCm = 4 outside the object, and we wanted to assign the value inside the object to the heightInCm outside, so we did it like a normal destructuring, BUT JavaScript expects a code block when starting with { } outside a function, so we wrap the statement in parentheses to make it valid.



*Nested object destructuring:




CODE
// firstway:  Extracting the Entire Nested Object 

const { details } = obj.home;
console.log(details); // { rooms: 3, uniqueFeature: "it's underwater and shaped like a pineapple"


// second way: Extracting Specific Properties
const {
home: { details }} = obj;

console.log(details); // {rooms: 3, uniqueFeature: "it's underwater and shaped like a pineapple"


// third way
const {details: { rooms, uniqueFeature }} = obj.home;

console.log(rooms, uniqueFeature); // 3 "it's underwater and shaped like a pineapple!"







  • Best for clarity: The first way can be better when you're working with larger objects and prefer to keep things clear by extracting a whole object first.

  • Best for efficiency: The third way is often the best if you're only interested in specific properties from a deeply nested object. It's concise and avoids creating unnecessary variables.



*Thanks for reading, hope you understand everything, if you have any questions feel free to ask 😊

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten JavaScript Object Destructuring

Thematisch verwandte Begriffe: JavaScript, Object, Destructuring · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...