Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Combine Objects with the Spread Operator | Advanced Object Manipulation Techniques
JavaScript Data Structures

bookChallenge: Combine Objects with the Spread Operator

Task

Create a script that performs the following tasks:

  • Merge the properties of two objects, personInfo and jobInfo, and store them in a new object named fullInfo.
  • Add a new property to the fullInfo object named isRetired with a value of false.
  • Use a for...in loop to iterate through fullInfo, and log each property and its corresponding value in the format: [property]: [value].
12345678910111213141516171819202122
const 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]); }
copy

Expected output:

name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
  1. Use the spread operator ({ ... }) to merge properties from personInfo and jobInfo into fullInfo.
  2. After merging, add a new property to fullInfo.
  3. Iterate through fullInfo using a for...in loop to log the properties and their values.
1234567891011121314151617181920
const 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]); }
copy

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 6

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

bookChallenge: Combine Objects with the Spread Operator

Task

Create a script that performs the following tasks:

  • Merge the properties of two objects, personInfo and jobInfo, and store them in a new object named fullInfo.
  • Add a new property to the fullInfo object named isRetired with a value of false.
  • Use a for...in loop to iterate through fullInfo, and log each property and its corresponding value in the format: [property]: [value].
12345678910111213141516171819202122
const 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]); }
copy

Expected output:

name: Ferry
age: 62
city: Caracas
experience: 7
occupation: Speech-Language Pathologist
isRetired: false
  1. Use the spread operator ({ ... }) to merge properties from personInfo and jobInfo into fullInfo.
  2. After merging, add a new property to fullInfo.
  3. Iterate through fullInfo using a for...in loop to log the properties and their values.
1234567891011121314151617181920
const 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]); }
copy

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 6
some-alt