The includes()
method of the IDBKeyRange
interface returns a boolean indicating whether a specified key is inside the key range.
var isIncluded = myKeyRange.includes(key)
key The key you want to check for in your key range. This can be any type.
A Boolean
.
This method may raise a DOMException
of the following type:
Attribute | Description |
---|---|
DataError | The supplied key was not a valid key. |
var keyRangeValue = IDBKeyRange.bound('A', 'K', false, false); var myResult = keyRangeValue.includes('F'); // Returns true var myResult = keyRangeValue.includes('W'); // Returns false
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 | Status | Comment |
---|---|---|
Indexed Database API 2.0 The definition of 'includes()' in that specification. | Recommendation | |
Indexed Database API 2.0 The definition of 'includes()' in that specification. | Recommendation |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 52 | Yes | 47 | ? | 39 | 10.1 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 52 | 52 | Yes | ? | 39 | 10.1 | 6.0 |
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange/includes