javascript Object Property code example
Example 1: javascript list object properties
var person={"first_name":"Bill","last_name":"Jenner"}
var keys = Object.keys(person);
Example 2: add property to object javascript
let yourObject = {};
let yourKeyVariable = "yourKey";
yourObject[yourKeyVariable] = "yourValue";
yourObject["yourKey"] = "yourValue";
yourObject.yourKey = "yourValue";
Example 3: object literal javascript
var myObject = {
sProp: 'some string value',
numProp: 2,
bProp: false
};
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
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
Example 6: Add New Properties to a JavaScript Object
var myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog.bark = "woof";
myDog["bark"] = "woof";