JavaScript There are more than one method to check it. First, we can use hasOwnProperty method. let object = {"one": 2, "tree": "floor", 5: "socks"}; console.log(object.hasOwnProperty("tree")); // true console.log(object.hasOwnProperty(4)); // false // (Not in the object) We'll expect boolean output. Second, we can use in operator. let object = {"one": 2, "tree": "floor", 5: "socks"}; console.log("tree" in object); // true console.log(4 in object); // false // (Not in the object) We'll expect boolean output. Third, directly access the property name we need to check. let object = {"one": 2, "tree": "floor", 5: "socks"}; console.log(object.tree); // "floor" // (Value of that property) console.log(object[4]); // undefined // (Undefined value from that given property name in the object) We'll expect th...
Reflections on ECMAScript (JavaScript), CSS, HTML, Blogger, technical fixes, literature, music, cinema, entertainment in general, the English language, mathematics, history, trousers-related, and curiosities of the realm.