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
course content

Course Content

JavaScript Data Structures

JavaScript Data Structures

1. Introduction and Prerequisites
2. Fundamentals of JavaScript Objects
3. Advanced Object Manipulation Techniques
4. Mastering JavaScript Arrays
5. Advanced Array Methods and Transformations

book
Challenge: 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:

  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
We're sorry to hear that something went wrong. What happened?
some-alt