0
admin
// Sample object const obj = { key1: 'value1', key2: 'value2', key3: 'value3' }; // Function to check if key exists function keyExists(obj, key) { return obj.hasOwnProperty(key); } // Example usage const keyToCheck = 'key2'; if (keyExists(obj, keyToCheck)) { console.log(`Key "${keyToCheck}" exists in the object.`); } else { console.log(`Key "${keyToCheck}" does not exist in the object.`); }
0 Subscribers
Submit Answer
0 Answers