How do I check if a particular key exists in a JavaScript object or array?
If a key doesn\'t exist, and I try to access it, will it return false? Or throw an error?<
const object1 = { a: 'something', b: 'something', c: 'something' }; const key = 's'; // Object.keys(object1) will return array of the object keys ['a', 'b', 'c'] Object.keys(object1).indexOf(key) === -1 ? 'the key is not there' : 'yep the key is exist';