Sfida: Combinare Oggetti con l'Operatore Spread
Compito
Crea uno script che esegua le seguenti operazioni:
- Unisci le proprietà di due oggetti,
personInfoejobInfo, e salvale in un nuovo oggetto chiamatofullInfo. - Aggiungi una nuova proprietà all'oggetto
fullInfochiamataisRetiredcon valorefalse. - Utilizza un ciclo
for...inper iterare sufullInfoe registra ogni proprietà e il relativo valore nel formato:[property]: [value].
12345678910111213141516171819202122const personInfo = { name: "Ferry", age: 62, city: "Caracas", }; const jobInfo = { experience: 7, occupation: "Speech-Language Pathologist", }; // Task 1: merge two objects const fullInfo = { ...___, ___, ___: ___, // Task 2: add the property }; // Task 3: log each property and its value for (let key in ___) { console.log(`${___}:`, ___[key]); }
Output atteso:
name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
- Utilizzare l'operatore spread (
{ ... }) per unire le proprietà dipersonInfoejobInfoinfullInfo. - Dopo l'unione, aggiungere una nuova proprietà a
fullInfo. - Iterare su
fullInfoutilizzando un ciclofor...inper registrare le proprietà e i loro valori.
1234567891011121314151617181920const personInfo = { name: "Ferry", age: 62, city: "Caracas", }; const jobInfo = { experience: 7, occupation: "Speech-Language Pathologist", }; const fullInfo = { ...personInfo, ...jobInfo, isRetired: false, }; for (let key in fullInfo) { console.log(`${key}:`, fullInfo[key]); }
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 6
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 2.27
Sfida: Combinare Oggetti con l'Operatore Spread
Scorri per mostrare il menu
Compito
Crea uno script che esegua le seguenti operazioni:
- Unisci le proprietà di due oggetti,
personInfoejobInfo, e salvale in un nuovo oggetto chiamatofullInfo. - Aggiungi una nuova proprietà all'oggetto
fullInfochiamataisRetiredcon valorefalse. - Utilizza un ciclo
for...inper iterare sufullInfoe registra ogni proprietà e il relativo valore nel formato:[property]: [value].
12345678910111213141516171819202122const personInfo = { name: "Ferry", age: 62, city: "Caracas", }; const jobInfo = { experience: 7, occupation: "Speech-Language Pathologist", }; // Task 1: merge two objects const fullInfo = { ...___, ___, ___: ___, // Task 2: add the property }; // Task 3: log each property and its value for (let key in ___) { console.log(`${___}:`, ___[key]); }
Output atteso:
name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
- Utilizzare l'operatore spread (
{ ... }) per unire le proprietà dipersonInfoejobInfoinfullInfo. - Dopo l'unione, aggiungere una nuova proprietà a
fullInfo. - Iterare su
fullInfoutilizzando un ciclofor...inper registrare le proprietà e i loro valori.
1234567891011121314151617181920const personInfo = { name: "Ferry", age: 62, city: "Caracas", }; const jobInfo = { experience: 7, occupation: "Speech-Language Pathologist", }; const fullInfo = { ...personInfo, ...jobInfo, isRetired: false, }; for (let key in fullInfo) { console.log(`${key}:`, fullInfo[key]); }
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 6