SealedCreates a list 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). null and
undefined elements are stored.
Time: O(m) for m elements.
Optionalelements: Iterable<E, any, any> | null
The initial elements.
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 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 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).
'LinkedList', 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: LinkedList(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 list, so calls chain.
Time: O(1).
The element to add.
The list.
Adds every element of elements at the end, in order, after reading them all (so a list can
add itself).
Time: O(m) for m elements.
The elements to add.
true when any element was added.
Adds element at the front and returns the list.
Time: O(1).
The element to add.
The list.
Adds element at the front, as addFirst does, and returns its handle.
Time: O(1).
The element to add.
The new element's handle.
Adds element at the end and returns the list; the same as add.
Time: O(1).
The element to add.
The list.
Adds element at the end, as addLast does, and returns its handle.
Time: O(1).
The element to add.
The new element's handle.
Returns a new LinkedList 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 list. Lists compare by identity; compare toArray() to
compare contents. Called through a Proxy of the list, it is true for that proxy too; the list itself
does not know its proxies, so list.equals(proxy) is false.
Time: O(1).
Any value.
true when other is this list.
Returns the handle of the first element, or undefined when the list is empty.
Time: O(1).
The first handle, or undefined.
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 (null and
undefined included).
Time: O(n).
The value to look for.
true when present.
Inserts element immediately after the element of node and returns the new handle.
Time: O(1).
A handle of an element of this list.
The element to insert.
The new element's handle.
Inserts element immediately before the element of node and returns the new handle.
Time: O(1).
A handle of an element of this list.
The element to insert.
The new element's handle.
Returns the handle of the last element, or undefined when the list is empty.
Time: O(1).
The last handle, or undefined.
Returns the first element without removing it, or undefined when the list is empty (or the
first element is undefined; isEmpty() tells them apart).
Time: O(1).
The first element, or undefined.
Returns the last element without removing it, or undefined when the list is empty (or the
last element is undefined; isEmpty() tells them apart).
Time: O(1).
The last element, or undefined.
Removes and returns the first element, or returns undefined when the list is empty. A stored
undefined is returned as well: check isEmpty() first to tell them apart.
Time: O(1).
The removed element, or undefined.
Removes and returns the last element (a stored undefined included), or returns undefined
when the list 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 list. Unlike
Array.prototype.push, it returns the list, not the new length.
Time: O(1).
The element to add.
The list.
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 the element of node and returns it. Afterwards the handle's next and previous
are undefined and its value can still be read.
Time: O(1).
A handle of an element of this list.
The removed element.
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 list in reverse order: its first element is this list's last,
and changes through either show in both (the view's push adds at this list's front, its
poll is this list's pop). reversed().reversed() returns this list.
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 list as an array.
Time: O(n).
A new array.
Static[hasReturns whether value is a LinkedList, including one created by another copy of the
library with the same major version. A reversed view is not a LinkedList.
Time: O(1).
The value on the left of instanceof.
true when value is a LinkedList.
StaticfromReturns a new list of the elements of elements, in order, like Array.from but for
iterables only.
Time: O(m) for m elements.
The elements.
A new list.
Returns a new list 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 list.
A double-ended queue stored as a doubly linked list, whose node handles allow O(1) insertion and removal next to a known element: moving an entry to the front of a cache, inserting next to a cursor, unlinking a cancelled task. It works wherever a
Dequeis expected:add+pollas a queue,push+popat the end as a stack.addFirstNode,addLastNode,insertBeforeandinsertAfterreturn a handle (LinkedListNode);removeNode,insertBeforeandinsertAftertake one. Each element has one handle for as long as it is in the list. There is no index access; useArrayListfor that.nullandundefinedare stored, as in an array, sopoll(),peek()andpop()can return a storedundefined: readisEmpty()(or useremoveFirst,getFirstand the other throwing forms) to tell "empty" apart. Two lists are equal only when they are the same object; comparetoArray()results to compare contents. Adding or removing while iterating throwsConcurrentModificationError; walking by handles never does.The class is not designed to be subclassed.
Example