Answers for "Add New Properties to a JavaScript Object"

14

how to add property to object in javascript

var data = {
    'PropertyA': 1,
    'PropertyB': 2,
    'PropertyC': 3
};

data["PropertyD"] = 4;

// dialog box with 4 in it
alert(data.PropertyD);
alert(data["PropertyD"]);
Posted by: Guest on April-16-2020
2

Add New Properties to a JavaScript Object

var myDog = {
  "name": "Happy Coder",
  "legs": 4,
  "tails": 1,
  "friends": ["freeCodeCamp Campers"]
};

myDog.bark = "woof";
// or
myDog["bark"] = "woof";
Posted by: Guest on July-19-2020
0

add new properties to JS objects

person.nationality = "English";
Posted by: Guest on May-23-2021

Code answers related to "Add New Properties to a JavaScript Object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language