Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Merging Objects and Adding Properties | Advanced Object Manipulation
JavaScript Data Structures
course content

Зміст курсу

JavaScript Data Structures

JavaScript Data Structures

1. Introduction and Prerequisites
2. Objects Fundamentals
3. Advanced Object Manipulation
4. Mastering Arrays
5. Advanced Array Operations

Challenge: Merging Objects and Adding Properties

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]); }

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]); }

Все було зрозуміло?

Секція 3. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt