get value of property in object javascript code example
Example 1: javascript dynamically access object property
var person ={"first_name":"Billy","last_name":"Riley"};
var property_name="first_name";
alert(person[property_name]); //Dynamically access object property with bracket notation
Example 2: how to a property from a JavaScript object
delete myObject.regex;
// or,
delete myObject['regex'];
// or,
var prop = "regex";
delete myObject[prop];
/** Demo */
var myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
delete myObject.regex;
console.log(myObject);
Example 3: js create object with properties
var mycar = new Car('Eagle', 'Talon TSi', 1993);
Example 4: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}