Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if somethin exist in an object js

let result = targetObject.hasOwnProperty(propertyName);

let person = {
   firstName: 'John',
   lastName: 'Doe'
};

//Example 1
let result = person.hasOwnProperty('firstName');
console.log(result); // true


//Example 2
let result = person.hasOwnProperty('age');
console.log(result); // false

Source by www.javascripttutorial.net #
 
PREVIOUS NEXT
Tagged: #check #somethin #exist #object #js
ADD COMMENT
Topic
Name
9+6 =