javascript get object properties code example
Example 1: check the properties of an object in javascript
for (var name in object) {
if (object.hasOwnProperty(name)) {
}
}
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name');
hero.hasOwnProperty('realName');
Example 2: object keys javascript
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
Example 3: javascript list object properties
var person={"first_name":"Bill","last_name":"Jenner"}
var keys = Object.keys(person);
Example 4: get object name javascript
var a = {
name:'a',
'light': 'good',
'dark' : {
name: 'dark',
'black': 'bad',
'gray' : 'not so bad'
}
}
console.log(a.name,a.dark.name);