SealedMarks 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 lists so isList 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).
'ArrayList', for Object.prototype.toString. Time: O(1).
A number that changes on every change to the contents — adding, removing, replacing or sorting elements — 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. Time: as equals.
The value-equality protocol: equal lists give equal hashes. The value is unspecified. Time: O(n) plus element hashes.
Node's inspect hook: ArrayList(2) [ 1, 2 ] in console.log. Time: as toString.
Returns an iterator over the elements in index order.
Time: O(1) to create; O(1) per step.
A new iterator.
Appends element and returns the list, so calls chain.
Time: amortised O(1).
The element to append.
The list.
Appends every element of elements, in order, after reading them all.
Time: O(m) amortised for m elements.
The elements to append.
true when any element was added.
Inserts element at the front and returns the list.
Time: O(n).
The element to insert.
The list.
Appends element and returns the list; the same as add.
Time: amortised O(1).
The element to append.
The list.
Returns a cursor positioned before the first element; the same as listCursor().
Time: O(1).
A new cursor.
Removes the first element equal to element under SameValueZero. To remove by position, use
removeAt: on a list of numbers, delete(1) removes the value 1, not index 1.
Time: O(n).
The value to remove.
true when an element was removed.
Returns whether other is a list (any implementation or view, from any copy of the package)
with the same size whose elements are equal in order under equals(a, b).
Time: O(n) plus element comparisons.
Any value.
true when equal.
Calls action(element, index, list) for each element in index order, with this set to
thisArg, as Array.prototype.forEach does.
Time: O(n) plus the calls.
Returns the element at index.
Time: O(1).
An integer with 0 <= index < size.
The element.
Returns whether some element is equal to element under SameValueZero.
Time: O(n).
The value to look for.
true when present.
Returns the lowest index whose element is equal to element under SameValueZero, or -1.
Unlike Array.prototype.indexOf, NaN is found.
Time: O(n).
The value to look for.
The index, or -1.
Inserts element at index, shifting later elements up by one, and returns the list.
Time: O(size − index).
An integer with 0 <= index <= size.
The element to insert.
The list.
Inserts every element of elements at index, in order, after reading them all; a list may
insert itself.
Time: O(size + m) for m elements.
An integer with 0 <= index <= size.
The elements to insert.
true when any element was inserted.
Returns the highest index whose element is equal to element under SameValueZero, or -1.
Time: O(n).
The value to look for.
The index, or -1.
Returns a cursor positioned before index (0 when omitted) that moves both ways and can
replace, insert and remove at its position.
Time: O(1).
Optionalindex: number
An integer with 0 <= index <= size.
A new cursor.
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.
Removes and returns the element at index, shifting later elements down by one.
Time: O(size − index).
An integer with 0 <= index < size.
The removed element.
Calls predicate(element, index, list) on every element (indexes before any removal), then
removes those for which it returned a truthy value, as Array.prototype.filter reads its
callback. An error from predicate removes nothing.
Time: O(n) plus the calls.
true when any element was removed.
Replaces each element with op(element, index, list), in index order. If op throws, the
elements before it are already replaced and the rest are unchanged. Open iterators stay valid.
Time: O(n) plus the calls.
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.
Sorts the list in place, keeping equal elements in their order (stable), and returns it.
Without a comparator, natural order is used (numbers by value, strings by code unit, …).
Unlike Array.prototype.sort, null and undefined reach the comparator like any other
element (natural order rejects them: sort with nullsLast(naturalOrder()) to put them last),
and a comparator result that is not a number throws. If anything throws, the sort itself
writes nothing to the list.
Time: O(n log n); at most n·⌈log₂ n⌉ comparator calls.
Optionalcomparator: Comparator<E>
The order; natural order when omitted.
The list.
Returns a live view of the elements from from (inclusive) to to (exclusive). Changes
through the view reach this list. Once this list is changed structurally (elements added or
removed, or a sort) other than through the view, the view throws
ConcurrentModificationError.
Time: O(1); each operation on the view costs what it costs on this list at the mapped index; a change of size also updates each enclosing sub-list, one step per level of nesting.
Start of the range, inclusive.
End of the range, exclusive.
The 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 an ArrayList, including one created by another copy of the
library with the same major version. Views (subList, reversed) are not ArrayLists.
Time: O(1).
The value on the left of instanceof.
true when value is an ArrayList.
StaticfromReturns 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 list stored in an array: indexed reads and writes in O(1), appends in amortised O(1), inserts and removals in time proportional to the elements after the position. Elements may be anything,
nullandundefinedincluded.Unlike an array, an index out of range throws
IndexOutOfBoundsErrorinstead of readingundefined;delete(element)removes by value;subListandreversedare live views; and adding, removing or sorting while iterating throwsConcurrentModificationError(use a cursor to change the list while iterating).indexOf,hasanddeletecompare with SameValueZero, soNaNis found;equalscompares two lists element by element withequals(a, b).The class is not designed to be subclassed.
Example