We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Updating Properties

You can update and add new keys (you'll see me use the words "property" and "key" interchangeably in this course) to an existing object using the . operator. If it exists, it's updated; if it doesn't, it's created as a new property:

const apple = {
  name: "Apple",
  radius: 2,
  color: "red",
};

apple.numSeeds = 3; // new property
apple.color = "green"; // update property
// {"name":"Apple","radius":2,"color":"green","numSeeds":3}

Assignment

In Textio, users create text campaigns to send messages to their contacts. Each campaign needs a unique ID for tracking and management.

Complete the addID function. It takes a campaignRecord object as input and returns it with a newly generated string id property. The id should be created by joining campaignName and senderName with a hyphen (-). For example:

summerSales-adam

Where campaignName and senderName are already properties of the campaignRecord object.