Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by h.daily-dev-tips.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #check #property #exists #Object
ADD COMMENT
Topic
Name
6+8 =