get attributes of object javascript code example

Example 1: javascript list object properties

var person={"first_name":"Bill","last_name":"Jenner"}
//get the person object properties with:
var keys = Object.keys(person); //keys = ["first_name","last_name"]

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: get object name javascript

var a = {
    name:'a',
    'light': 'good',
    'dark' : {
         name: 'dark',
        'black': 'bad',
        'gray' : 'not so bad'
    }
}

// This way you can do

console.log(a.name,a.dark.name);