To find out if a property exists on an object we can use in operator:
var school = {schoolName:"MIT"};
console.log("schoolName" in school);  // true because schoolName is an own property on the school object

console.log("schoolType" in school);  // false because  because we did not define a schoolType property on the school object

// Prints true because the school object inherited the toString method from Object.prototype. 
console.log("toString" in school);  // true
by Luka Tatarishvili
4 years ago
JavaScript
objects
0
Pro tip: use ```triple backticks around text``` to write in code fences