Last active
February 24, 2025 09:24
-
-
Save bhaireshm/b379722e38978cab80c639931001db64 to your computer and use it in GitHub Desktop.
Checks for the key in the given object. Can check multiple keys at once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {Object} obj | |
| * @param {String} keys : keys seperated by comma | |
| * Example : console.log( hasOwnProperty({'a':1, 'b':2, 'c':3}, "a,d") ); | |
| */ | |
| const hasOwnProperty = (obj, keys) => { | |
| if(Object.entries(obj).length == 0 || keys.length == 0) return false; | |
| else return keys.split(",").map((k) => { | |
| if(k != "" && !Object.hasOwnProperty.call(obj, k)) return `${k} not found`; | |
| }).filter(a=> typeof a == 'string')[0] || "All key(s) found"; | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.