Answers for "js change object value"

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
1

js change object value

var myObject = { boo: true, baa: 5 };
console.log(myObject); 
// expected output: 
// { boo: true, baa:5}

myObject.boo = false;
myObject.baa++;
console.log(myObject); 
// expected output: 
// { boo: false, baa:6}
Posted by: Guest on July-29-2021
0

JavaScript: Updating Object Properties

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

// Update the name value
myDog.name = "Happy Coder";
Posted by: Guest on July-19-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language