how to access a property of an object in javascript code example

Example 1: js obj

var obj = {my:"sql",  nice:[69, 420]};

obj.my //returns the string "sql"
obj.nice //returns the array [69, 420]

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: javascript object string property

// Also useful for dynamic strings, e.g. `thing-${variable}`
myObject['thing'] = true;

Example 4: objects in javascript

let name = {
	name1: 'mark'
}

Tags:

Misc Example