object properties in javascript code example
Example 1: creating an object javascript
let obj = {
name:"value",
num: 123,
foo: function(){}
}
Example 2: javascript list object properties
var person={"first_name":"Bill","last_name":"Jenner"}
var keys = Object.keys(person);
Example 3: adding function to objects js
var myObj = {
myFunc: function(param){
}
}
Example 4: 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 5: js create object with properties
var mycar = new Car('Eagle', 'Talon TSi', 1993);
Example 6: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}