javascript-collections-framework
    Preparing search index...

    Interface ReadonlyList<E>

    The read-only view of a list: ordered, indexed from 0, duplicates allowed.

    function middle<E>(list: ReadonlyList<E>): E {
    return list.get(list.size >> 1)
    }
    interface ReadonlyList<E> {
        revision: number;
        size: number;
        "[equalsSymbol]"(other: unknown): boolean;
        "[hashCodeSymbol]"(hash: HashFunction): number;
        "[iterator]"(): IterableIterator<E>;
        cursor(): Cursor<E>;
        equals(other: unknown): boolean;
        forEach(
            action: (element: E, index: number, list: ReadonlyList<E>) => void,
            thisArg?: unknown,
        ): void;
        get(index: number): E;
        getFirst(): E;
        getLast(): E;
        has(element: E): boolean;
        indexOf(element: E): number;
        isEmpty(): boolean;
        lastIndexOf(element: E): number;
        listCursor(index?: number): ListCursor<E>;
        reversed(): ReadonlyList<E>;
        subList(from: number, to: number): ReadonlyList<E>;
        toArray(): E[];
        toJSON(): E[];
        toString(): string;
    }

    Type Parameters

    • E

    Hierarchy (View Summary)

    Index
    revision: number

    A number that changes on every change to the contents — adding, removing or replacing an element — and never on a read. Watch it to detect changes; its exact values are unspecified. Time: O(1).

    size: number

    The number of elements. Time: O(1).

    • The value-equality protocol; delegates to equals. Time: as equals.

      Parameters

      • other: unknown

      Returns boolean

    • Returns an iterator over the elements in iteration order.

      Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.

      Returns IterableIterator<E>

      A new iterator.

      ConcurrentModificationError (from next()) when elements of a fail-fast collection are added or removed after the iterator is created, including through a cursor.

    • Returns whether other is equal to this collection, as the collection's family defines; otherwise only the collection itself. Time: as the implementation documents.

      Parameters

      • other: unknown

        Any value.

      Returns boolean

      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.

      Parameters

      • action: (element: E, index: number, list: ReadonlyList<E>) => void

        Called with each element, its index and the list.

      • OptionalthisArg: unknown

        The this value for action.

      Returns void

      TypeError when action is not a function.

      ConcurrentModificationError when action adds or removes elements.

    • Returns the element at index.

      Time: as the implementation documents.

      Parameters

      • index: number

        An integer with 0 <= index < size.

      Returns E

      The element.

      IndexOutOfBoundsError when index is not an integer in range.

    • Returns the first element.

      Time: as the implementation documents.

      Returns E

      The first element.

      NoSuchElementError when the collection is empty.

    • Returns the last element.

      Time: as the implementation documents.

      Returns E

      The last element.

      NoSuchElementError when the collection is empty.

    • Returns whether some element is equal to element under the collection's equality (SameValueZero unless the collection says otherwise). Time: as the implementation documents.

      Parameters

      • element: E

        The value to look for.

      Returns boolean

      true when an equal element is present.

    • Returns the lowest index whose element is equal to element under SameValueZero (so NaN is found), or -1.

      Time: O(n).

      Parameters

      • element: E

        The value to look for.

      Returns number

      The index, or -1.

    • Returns the highest index whose element is equal to element under SameValueZero, or -1.

      Time: O(n).

      Parameters

      • element: E

        The value to look for.

      Returns number

      The index, or -1.

    • Returns a cursor positioned before index (0 when omitted).

      Time: O(1).

      Parameters

      • Optionalindex: number

        An integer with 0 <= index <= size.

      Returns ListCursor<E>

      A new cursor.

      IndexOutOfBoundsError when index is not an integer in range.

    • Returns a live view of the elements from from (inclusive) to to (exclusive). Once the list's structure changes other than through the view, the view throws ConcurrentModificationError.

      Time: O(1).

      Parameters

      • from: number

        Start of the range, inclusive.

      • to: number

        End of the range, exclusive.

      Returns ReadonlyList<E>

      The view.

      IndexOutOfBoundsError when from < 0, to > size or a bound is not an integer.

      IllegalArgumentError when from > to.

    • Returns a new array of the elements in iteration order; changing it does not change the collection.

      Time: O(n).

      Returns E[]

      A new array.

    • Returns a new array of the elements, so JSON.stringify writes the collection as an array.

      Time: O(n).

      Returns E[]

      A new array.

    • Returns the class name, size and elements, e.g. ArrayList(3) [1, 2, 'a'].

      Time: O(length of the output) for flat contents; each level of nested arrays or collections copies its text once more.

      Returns string

      The text.