Course Content
JavaScript Data Structures
JavaScript Data Structures
Challenge: Merging Objects and Adding Properties
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]
.
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:
- 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.
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]); }
Thanks for your feedback!