Answers for "javascript identify object property"

5

How to tell if an attribute exists on an object

const user = {
    name: "Sicrano",
    age: 14
}

user.hasOwnProperty('name');       // Retorna true
user.hasOwnProperty('age');        // Retorna true
user.hasOwnProperty('gender');     // Retorna false
user.hasOwnProperty('address');    // Retorna false
Posted by: Guest on October-26-2020
0

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);
Posted by: Guest on October-13-2020

Code answers related to "javascript identify object property"

Code answers related to "Javascript"

Browse Popular Code Answers by Language