Destructuring and Spread
Sveip for å vise menyen
Destructuring allows you to extract values from objects and arrays into variables.
const user = {
name: "John",
age: 25
};
const { name, age } = user;
Now you can use name and age directly instead of accessing them through the object.
You can also use destructuring with arrays:
const numbers = [10, 20];
const [first, second] = numbers;
The spread operator (...) is used to copy or merge data.
const user = { name: "John" };
const updatedUser = {
...user,
age: 25
};
This creates a new object with all existing data plus new values.
Destructuring and spread are commonly used when working with data, especially in backend code where objects are passed and modified frequently.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 10
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Seksjon 1. Kapittel 10