SealedCreates a deque holding the elements of elements, in order (the first is the front); empty
when elements is omitted, undefined or null (as new Set(null) is).
Time: O(m) for m elements.
Optionalelements: Iterable<E, any, any> | null
The initial elements.
Marks instances of this class so instanceof recognises them across copies of the package.
Its key is not exported, so the getter is not called directly. Time: O(1).
Marks collections so isCollection recognises them across copies of the package. Its key is
not exported, so the getter is not called directly. Time: O(1).
Marks deques so isDeque recognises them across copies of the package. Its key is not
exported, so the getter is not called directly. Time: O(1).
Marks queues so isQueue recognises them across copies of the package. Its key is not
exported, so the getter is not called directly. Time: O(1).
Marks sequenced collections so isSequencedCollection recognises them across copies of the
package. Its key is not exported, so the getter is not called directly. Time: O(1).
'ArrayDeque', for Object.prototype.toString. Time: O(1).
A number that changes on every change to the contents and never on a read. Its exact values are unspecified. Time: O(1).
The number of elements. Time: O(1).
The value-equality protocol; delegates to equals (identity). Time: O(1).
The value-equality protocol: an identity hash, unspecified in value. Time: O(1).
Node's inspect hook: ArrayDeque(2) [ 1, 2 ] in console.log. Time: as toString.
Returns an iterator over the elements from first to last.
Time: O(1) to create; O(1) per step.
A new iterator.
Adds element at the end and returns the deque, so calls chain.
Time: amortised O(1).
The element to add.
The deque.
Adds every element of elements at the end, in order, after reading and checking them all:
if any is null or undefined, nothing is added.
Time: amortised O(m) for m elements.
The elements to add.
true when any element was added.
Adds element at the front and returns the deque.
Time: amortised O(1).
The element to add.
The deque.
Adds element at the end and returns the deque; the same as add.
Time: amortised O(1).
The element to add.
The deque.
Returns a new ArrayDeque with the same elements in the same order, independent of this one
(the elements themselves are not copied).
Time: O(n).
The copy.
Removes the first element equal to element under SameValueZero, searching from the front.
reversed().delete(element) removes the last one instead.
Time: O(n).
The value to remove.
true when an element was removed.
Returns whether other is this deque. Deques compare by identity; compare toArray() to
compare contents. Called through a Proxy of the deque, it is true for that proxy too; the deque itself
does not know its proxies, so deque.equals(proxy) is false.
Time: O(1).
Any value.
true when other is this deque.
Calls action(element) for each element from first to last, with this set to thisArg.
Time: O(n) plus the calls.
Called with each element.
OptionalthisArg: unknown
The this value for action.
Returns whether some element is equal to element under SameValueZero; always false for
null and undefined.
Time: O(n).
The value to look for.
true when present.
Returns the first element without removing it, or undefined when the deque is empty.
Time: O(1).
The first element, or undefined.
Returns the last element without removing it, or undefined when the deque is empty.
Time: O(1).
The last element, or undefined.
Removes and returns the first element, or returns undefined when the deque is empty.
Time: O(1).
The removed element, or undefined.
Removes and returns the last element, or returns undefined when the deque is empty, as
Array.prototype.pop does.
Time: O(1).
The removed element, or undefined.
Adds element at the end, as add does, and returns the deque. Unlike
Array.prototype.push, it returns the deque, not the new length.
Time: amortised O(1).
The element to add.
The deque.
Removes every element equal to one in elements (SameValueZero). Decides first, so an error
while deciding removes nothing.
Time: O(n + m) for m elements.
The elements to remove.
true when any element was removed.
Calls predicate(element) on every element, then removes those for which it returned a truthy
value; an error from predicate removes nothing.
Time: O(n) plus the calls.
Called with each element.
true when any element was removed.
Removes every element not equal to one in elements (SameValueZero). Decides first, so an
error while deciding removes nothing.
Time: O(n + m) for m elements.
The elements to keep.
true when any element was removed.
Returns a live view of this deque in reverse order: its first element is this deque's last,
and changes through either show in both (the view's push adds at this deque's front, its
poll is this deque's pop). reversed().reversed() returns this deque.
Time: O(1); each operation on the view costs what its mirror costs.
The reversed view.
Returns a new array of the elements, so JSON.stringify writes the deque as an array.
Time: O(n).
A new array.
Static[hasReturns whether value is an ArrayDeque, including one created by another copy of the
library with the same major version. A reversed view is not an ArrayDeque.
Time: O(1).
The value on the left of instanceof.
true when value is an ArrayDeque.
StaticfromReturns a new deque of the elements of elements, in order, like Array.from but for
iterables only.
Time: O(m) for m elements.
The elements.
A new deque.
Returns a new deque of mapFn(element, index) for each element of elements, in order, with
this set to thisArg, as Array.from does. elements is read while mapFn runs, so
items mapFn appends to an array source are included.
Time: O(m) plus the calls.
A new deque.
A double-ended queue stored in a circular array: adding at either end is amortised O(1) and removing is O(1), so it serves as a first-in-first-out queue (
add+poll), as a stack (push+pop, at the end, as on an array) or as a buffer worked from both ends.nullandundefinedare not allowed as elements, sopoll(),peek()andpop()returningundefinedalways means the deque is empty. Two deques are equal only when they are the same object; comparetoArray()results to compare contents. Adding or removing while iterating throwsConcurrentModificationError; use a cursor to remove while iterating.The class is not designed to be subclassed.
Example