Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn 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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 6

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 6
some-alt