https://github.com/afaur/objhas
Find out if a js object (used as a dictionary/hash) has a property nested within.
https://github.com/afaur/objhas
Last synced: 10 months ago
JSON representation
Find out if a js object (used as a dictionary/hash) has a property nested within.
- Host: GitHub
- URL: https://github.com/afaur/objhas
- Owner: afaur
- License: unlicense
- Created: 2017-12-01T23:23:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-04T18:25:26.000Z (over 8 years ago)
- Last Synced: 2025-06-12T22:40:09.508Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://afaur.github.io/objHas/
- Size: 268 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Why?
Need to determine if a nested property exists with a value (see caveats listed below).
# Other solutions exist
Why make this when many other solutions are out there?
- Solutions have been proposed along with benchmarks of performace for each...
- [Stack Overflow](https://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key)
# What makes this different?
I do not believe this is by any means the best solution but...
- All code is [documented](https://afaur.github.io/objHas/)
- Has tests to ensure it handles your expected behavior (Look at `./bin/test`)
- If a property exists but has a value of...
- undefined - method will return `false`.
- empty array - method will return `true`.
- number 0 - method will return `false`.
- ...and many more so please look at the tests (`./bin/test`)
- Uses a for loop instead of recursion.
- [Stack Exchange](https://softwareengineering.stackexchange.com/questions/179863/performance-recursion-vs-iteration-in-javascript)
- Is meant to be copy and pasted into your project and not installed through npm
# Versions
Identical except that `compatibility` will work without new language features.
- Latest (`./lib/objHas.js`)
- Uses `const` and `let`
- Uses `rest` parameters
- Uses `arrow` functions
- Compatiblity (`./lib/.objHas.js`)
- Uses `var`
- Uses `Array.prototype.slice` on arguments
- Uses `function`
# Run Tests (latest version)
```$ make```
# Run Tests (compatiblity version)
```$ make test```