how to access the property of an object javascript code example
Example 1: how to add property to object in javascript
var data = {
'PropertyA': 1,
'PropertyB': 2,
'PropertyC': 3
};
data["PropertyD"] = 4;
alert(data.PropertyD);
alert(data["PropertyD"]);
Example 2: js objects
const dog = {
name: "Rusty",
breed: "unknown",
isAlive: false,
age: 7
}
dog.age;
dog["age"];
dog.breed = "mutt";
dog["age"] = 8;
Example 3: how to a property from a JavaScript object
delete myObject.regex;
delete myObject['regex'];
var prop = "regex";
delete myObject[prop];
var myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
delete myObject.regex;
console.log(myObject);
Example 4: objects in javascript
let name = {
name1: 'mark'
}