4.7. The IDBKeyRange interface
The [IDBKeyRange](#idbkeyrange)
interface represents a key range.
- [Exposed=(Window,Worker)]
- interface
IDBKeyRange
{- readonly attribute any lower;
- readonly attribute any upper;
- readonly attribute boolean lowerOpen;
- readonly attribute boolean upperOpen;
- // Static construction methods:
- [NewObject] static IDBKeyRange only(any
value
);- [NewObject] static IDBKeyRange
lowerBound
(anylower
, optional booleanopen
= false);- [NewObject] static IDBKeyRange
upperBound
(anyupper
, optional booleanopen
= false);- [NewObject] static IDBKeyRange bound(any
lower
,- any
upper
,- optional boolean
lowerOpen
= false,- optional boolean
upperOpen
= false);- boolean
_includes
(anykey
);- };
Note: When mapping the _includes
identifier to ECMAscript, the leading U+005F LOW LINE (“_“) character should be removed. A leading “_“ is used to escape the identifier from looking like a reserved word (in this case, the includes
keyword).
range . [lower](#dom-idbkeyrange-lower)
Returns lower bound, or undefined
if none.
range . [upper](#dom-idbkeyrange-upper)
Returns upper bound, or undefined
if none.
range . [lowerOpen](#dom-idbkeyrange-loweropen)
Returns true if the lower open flag is set, and false otherwise.
range . [upperOpen](#dom-idbkeyrange-upperopen)
Returns true if the upper open flag is set, and false otherwise.
The lower
attribute’s getter must return result of running the steps to convert a key to a value with the lower bound if it is not null, or undefined otherwise.
The upper
attribute’s getter must return the result of running the steps to convert a key to a value with the upper bound if it is not null, or undefined otherwise.
The lowerOpen
attribute’s getter must return true if the lower open flag is set, and false otherwise.
The upperOpen
attribute’s getter must return true if the upper open flag is set, and false otherwise.
range = [IDBKeyRange](#idbkeyrange)
. [only](#dom-idbkeyrange-only)
(key)
Returns a new [IDBKeyRange](#idbkeyrange)
spanning only key.
range = [IDBKeyRange](#idbkeyrange)
. [lowerBound](#dom-idbkeyrange-lowerbound)
(key [, open = false])
Returns a new [IDBKeyRange](#idbkeyrange)
starting at key with no upper bound. If open is true, key is not included in the range.
range = [IDBKeyRange](#idbkeyrange)
. [upperBound](#dom-idbkeyrange-upperbound)
(key [, open = false])
Returns a new [IDBKeyRange](#idbkeyrange)
with no lower bound and ending at key. If open is true, key is not included in the range.
range = [IDBKeyRange](#idbkeyrange)
. [bound](#dom-idbkeyrange-bound)
(lower, upper [, lowerOpen = false [, upperOpen = false]])
Returns a new [IDBKeyRange](#idbkeyrange)
spanning from lower to upper. If lowerOpen is true, lower is not included in the range. If upperOpen is true, upper is not included in the range.
The only(value)
method, when invoked, must run these steps:
Let key be the result of running the steps to convert a value to a key with value. Rethrow any exceptions.
If key is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Create and return a new key range containing only key.
The lowerBound(lower, lowerOpen)
method, when invoked, must run these steps:
Let lowerKey be the result of running the steps to convert a value to a key with lower. Rethrow any exceptions.
If lowerKey is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Create and return a new key range with lower bound set to lowerKey, lower open flag set if lowerOpen is true, upper bound set to null and upper open flag set.
The upperBound(upper, upperOpen)
method, when invoked, must run these steps:
Let upperKey be the result of running the steps to convert a value to a key with upper. Rethrow any exceptions.
If upperKey is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Create and return a new key range with lower bound set to null, lower open flag set, upper bound set if upperKey, and upper open flag set to upperOpen.
The bound(lower, upper, lowerOpen, upperOpen)
method, when invoked, must run these steps:
Let lowerKey be the result of running the steps to convert a value to a key with lower. Rethrow any exceptions.
If lowerKey is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Let upperKey be the result of running the steps to convert a value to a key with upper. Rethrow any exceptions.
If upperKey is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.If lowerKey is greater than upperKey, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Create and return a new key range with lower bound set to lowerKey, lower open flag set if lowerOpen is true, upper bound set to upperKey and upper open flag set if upperOpen is true.
range . [includes](#dom-idbkeyrange-includes)
(key)
Returns true if key is included in the range, and false otherwise.
The includes(key)
method, when invoked, must run these steps:
Let k be the result of running the steps to convert a value to a key with key. Rethrow any exceptions.
If k is invalid, throw a “
[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)
“[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException)
.Return true if k is in this range, and false otherwise.
🚧 The [includes()](#dom-idbkeyrange-includes)
method is new in this edition. It is supported in Chrome 52, Firefox 47, and Safari 10.1. 🚧