To find out if an object has a specific property as one of its own property. var school = {schoolName:"MIT"};


console.log(school.hasOwnProperty ("schoolName"));  // true because schoolName is an own property on the school object


// Prints false because the school object inherited the toString method from Object.prototype, therefore toString is not an own property of the school object.

console.log(school.hasOwnProperty ("toString"));  

by Luka Tatarishvili
4 years ago
JavaScript
objects
0
Pro tip: use ```triple backticks around text``` to write in code fences