includes( ) 方法在 IDBKeyRange interface returns a boolean indicating whether a specified key is inside the key range.

注意: 此特征可用于 Web 工作者 .

句法

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
						

Polyfill

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.
推荐

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
包括 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

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: