javascript-collections-framework
    Preparing search index...

    Interface Cursor<E>

    Walks a collection one element at a time and can remove the element it just returned.

    Unlike a JavaScript iterator, next() returns the element itself; a cursor is not iterable, so for…of over it is an error. Use it to filter a collection in place in one pass.

    const cursor = collection.cursor()
    while (cursor.hasNext()) {
    if (cursor.next() < 0) cursor.remove()
    }
    interface Cursor<E> {
        hasNext(): boolean;
        next(): E;
        remove(): void;
    }

    Type Parameters

    • E

    Hierarchy (View Summary)

    Index
    • Returns whether next() has an element to return. Never throws. Time: O(1) unless the collection documents otherwise.

      Returns boolean

    • Returns the next element.

      Time: O(1) unless the collection documents otherwise.

      Returns E

      The next element.

      NoSuchElementError when no element remains.

      ConcurrentModificationError when a fail-fast collection was changed other than through this cursor.

    • Removes the element the last next() returned.

      Time: as the implementation documents.

      Returns void

      IllegalStateError when called before next(), or twice without a next() between (on a list cursor, previous() counts as a move too).

      UnsupportedOperationError when the collection cannot be changed (a read-only view).

      ConcurrentModificationError when a fail-fast collection was changed other than through this cursor.