includes(
)
方法在
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
布尔
.
此方法可能引发
DOMException
of the following type:
| 属性 | 描述 |
|---|---|
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
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;
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
索引数据库 API 草案
The definition of 'includes()' in that specification. |
推荐 | |
|
索引数据库 API 草案
The definition of 'includes()' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
包括
|
Chrome 52 | Edge ≤18 | Firefox 47 | IE ? | Opera 39 | Safari 10.1 | WebView Android 52 | Chrome Android 52 | Firefox Android Yes | Opera Android 41 | Safari iOS 10.3 | Samsung Internet Android 6.0 |
完整支持
兼容性未知
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
IDBKeyRange
bound()
includes()
lowerBound()
only()
upperBound()
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBObjectStore
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest