@jiminp/tooltool
    Preparing search index...

    Function arrayGetOrExtend

    • Gets an element, extending with scalar values or shallow copies if out of bounds.

      Type Parameters

      • T

        Element type.

      Parameters

      • arr: T[]

        The dense array.

      • index: number

        Integer array index from 0 through 2 ** 32 - 2.

      • default_value: T

        Scalar value, plain record, or array template for new entries.

      Returns T

      The element at index.

      If index is not a valid array index.

      If extension requires copying an unsupported template.

      Scalars (including null and undefined) are stored unchanged. For objects, copies array elements or enumerable own record properties, retaining nested references. Object templates must have this realm's Object.prototype or Array.prototype, or a null prototype for records. Null-prototype records retain their null prototype. Existing entries are returned without inspecting the template. Use arrayGetOrExtendWith for built-ins, class instances, or templates from another realm.

      const rows: number[][] = [];
      arrayGetOrExtend(rows, 1, [0]); // [0]; rows is [[0], [0]]
      rows[0]!.push(1); // rows[1] remains [0]

      const values: bigint[] = [];
      arrayGetOrExtend(values, 2, 4n); // 4n; values is [4n, 4n, 4n]
      arrayGetOrExtend([], 0, "foo"); // "foo"
      arrayGetOrExtend([], 0, null); // null