← Back to challenges

Does the Object Contain a Given Key?

JavaScriptHardobjectslanguage_fundamentalsvalidation

Instructions

Write a function that returns true if a hash contains the specified key, and false otherwise.

Examples

hasKey({ a: 44, b: 45, c: 46 }, "d") ➞ false

hasKey({ craves: true, midnight: true, snack: true }, "morning") ➞ false

hasKey({ pot: 1, tot: 2, not: 3 }, "not") ➞ true

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Broken Bridge