The includes()
method of the IDBKeyRange
interface returns a boolean indicating whether a specified key is inside the key range.
Note: This feature is available in Web Workers.
Syntax
var isIncluded = myKeyRange.includes(key)
Parameters
key The key you want to check for in your key range. This can be any type.
Return value
A Boolean
.
Exceptions
This method may raise a DOMException
of the following type:
Attribute | Description |
---|---|
DataError
|
The supplied key was not a valid key. |
Example
var keyRangeValue = IDBKeyRange.bound('A', 'K', false, false);
var myResult = keyRangeValue.includes('F');
// Returns true
var myResult = keyRangeValue.includes('W');
// Returns false
Polyfill
The includes()
method was added in the second edition of the Indexed DB specification. For browsers that do not support it, the following polyfill can be used.
IDBKeyRange.prototype.includes = IDBKeyRange.prototype.includes || function(key) {
var r = this, c;
if (r.lower !== undefined) {
c = indexedDB.cmp(key, r.lower);
if (r.lowerOpen && c <= 0) return false;
if (!r.lowerOpen && c < 0) return false;
}
if (r.upper !== undefined) {
c = indexedDB.cmp(key, r.upper);
if (r.upperOpen && c >= 0) return false;
if (!r.upperOpen && c > 0) return false;
}
return true;
};
Specification
Specification | Status | Comment |
Indexed Database API DraftThe definition of 'includes()' in that specification. | Recommendation | |
Indexed Database API DraftThe definition of 'includes()' in that specification. | Recommendation |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
includes
|
Chrome
Full support 52 |
Edge
Full support ≤18 |
Firefox
Full support 47 |
IE
No support No |
Opera
Full support 39 |
Safari
Full support 10.1 |
WebView Android
Full support 52 |
Chrome Android
Full support 52 |
Firefox Android
Full support Yes |
Opera Android
Full support 41 |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
- Using IndexedDB
- Starting transactions:
IDBDatabase
- Using transactions:
IDBTransaction
- Setting a range of keys:
IDBKeyRange
- Retrieving and making changes to your data:
IDBObjectStore
- Using cursors:
IDBCursor
- Reference example: To-do Notifications ([[../../../../../../../mdn.github.io/to-do-notifications/index|view example live]].)
IDBKeyRange.includes() by Mozilla Contributors is licensed under CC-BY-SA 2.5.