javascript-collections-framework
    Preparing search index...

    Function unmodifiableList

    • Returns a read-only view of list: indexes, subList, reversed() and cursors read the list, so the owner's changes show through, and every change — on the view, its sub-lists and reversed views, and its cursors — throws UnsupportedOperationError before its arguments are checked. The view equals, and hashes like, the list.

      When list is already a view this function returns (printed as UnmodifiableList, its sub-lists and reversed views included), it is returned unchanged. When it is any other unmodifiable view or immutable collection from this copy of the library, the new view reads that collection's source instead, and entries it hands out stay read-only, so read-only wrappers never nest.

      Time: O(1); each operation costs what the list's costs.

      Type Parameters

      • E

      Parameters

      Returns ReadonlyList<E>

      list itself, or an unmodifiable view printed as UnmodifiableList.

      TypeError when list is not a list from this library.

      const items = new ArrayList(['a'])
      const view = unmodifiableList(items)
      items.add('b')
      view.get(1) // 'b'