Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

JavaScript check if property exists in Object

const userOne = {
  name: 'Chris Bongers',
  email: 'info@daily-dev-tips.com',
};

const userTwo = {
  name: 'John Do',
};

console.log(userOne.hasOwnProperty('email'));
// Returns: true

console.log(userTwo.hasOwnProperty('email'));
// Returns: false
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js stop 
Javascript :: javascript format currency 
Javascript :: run react native app in production mode 
Javascript :: js number 2 decimal places 
Javascript :: react bootstrap styles not working 
Javascript :: javacript string add space after commas 
Javascript :: onclick jquery show alert 
Javascript :: add classnames to body 
Javascript :: email validation using javascript 
Javascript :: nodejs command line arguments 
Javascript :: stop immediate propagation 
Javascript :: js update query string 
Javascript :: Could not resolve dependency error peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4 
Javascript :: before send ajax loading 
Javascript :: express server how to get request ip 
Javascript :: heroicons 
Javascript :: connection refused xmlhttprequest 
Javascript :: window.onload 
Javascript :: creating new react app 
Javascript :: document get element by tag 
Javascript :: javascript preload images 
Javascript :: is email js 
Javascript :: ng update angular material 
Javascript :: get page resolution jquery 
Javascript :: generate random ip address javascript 
Javascript :: uppercase angular pipe 
Javascript :: node js variable inside string 
Javascript :: react style justify content space between 
Javascript :: has key js 
Javascript :: carousel speed bootstrap 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =