@JaySODec 06, 2022 — #You can use the hasOwnProperty() method. This method returns a boolean value indicating whether the object has the specified property as its own property (as opposed to inheriting it).
if (object.hasOwnProperty("key1")) { // Do something if the object has the "key1" property }
You can also use the in operator to check if a specific key exists in an object or array. This operator returns a boolean value indicating whether the specified property exists in the object.
Example:
const array = ["value1", "value2"];
if ("key1" in array) { // Do something if the array has the "key1" property }
reply?
×
Success!
Help @hq spread the word by sharing this article on Twitter...