Challenge: Combine Objects with the Spread Operator
Task
Create a script that performs the following tasks:
- Merge the properties of two objects,
personInfo
andjobInfo
, and store them in a new object namedfullInfo
. - Add a new property to the
fullInfo
object namedisRetired
with a value offalse
. - Use a
for...in
loop to iterate throughfullInfo
, and log each property and its corresponding value in the format:[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]); }
Expected output:
name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
- Use the spread operator (
{ ... }
) to merge properties frompersonInfo
andjobInfo
intofullInfo
. - After merging, add a new property to
fullInfo
. - Iterate through
fullInfo
using afor...in
loop to log the properties and their values.
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]); }
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 6
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 2.27
Challenge: Combine Objects with the Spread Operator
Pyyhkäise näyttääksesi valikon
Task
Create a script that performs the following tasks:
- Merge the properties of two objects,
personInfo
andjobInfo
, and store them in a new object namedfullInfo
. - Add a new property to the
fullInfo
object namedisRetired
with a value offalse
. - Use a
for...in
loop to iterate throughfullInfo
, and log each property and its corresponding value in the format:[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]); }
Expected output:
name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
- Use the spread operator (
{ ... }
) to merge properties frompersonInfo
andjobInfo
intofullInfo
. - After merging, add a new property to
fullInfo
. - Iterate through
fullInfo
using afor...in
loop to log the properties and their values.
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]); }
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 6