Interface ReadonlyArray<T>

An array object which cannot be written to.

interface ReadonlyArray<T> {
    every(this, callback): boolean;
    filter<S>(this, callback): S[];
    filter(this, callback): T[];
    filterUndefined(this): NonNullable<T>[];
    find<S>(this, predicate): undefined | S;
    findIndex(this, predicate): number;
    forEach(this, callback): void;
    includes(this, searchElement, fromIndex?): boolean;
    indexOf(this, searchElement, fromIndex?): number;
    isEmpty(this): boolean;
    join(this, separator?): string;
    map<U>(this, callback): U[];
    mapFiltered<U>(this, callback): NonNullable<U>[];
    move(this, f, e, t, a2): T[];
    move(this, f, e, t, a2?): T[];
    reduce(this, callback): T;
    reduce<U>(this, callback, initialValue): U;
    size(): number;
    some(this, callback): boolean;
}

Type Parameters

  • T

Hierarchy

  • ArrayLike<T>
  • Iterable<T>
    • ReadonlyArray

Methods

  • Returns whether all the members of an array satisfy the specified test. Returns true for empty Arrays.

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => undefined | boolean)

      A function that accepts up to three arguments. The every method calls the callback function for each element in array1 until the callback returns false, or until the end of the array.

        • (value, index, array): undefined | boolean
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns undefined | boolean

    Returns boolean

  • Returns the elements of an array that meet the condition specified in a callback function.

    Type Parameters

    • S

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => value is S)

      A function that accepts up to three arguments. The filter method calls the callback function one time for each element in the array.

        • (value, index, array): value is S
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns value is S

    Returns S[]

  • Returns the elements of an array that meet the condition specified in a callback function.

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => undefined | boolean)

      A function that accepts up to three arguments. The filter method calls the callback function one time for each element in the array.

        • (value, index, array): undefined | boolean
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns undefined | boolean

    Returns T[]

  • Removes all undefined values from the array safely

    Parameters

    • this: undefined extends T
          ? readonly T[]
          : never

    Returns NonNullable<T>[]

  • Returns the value of the first element in the array where predicate is true, and undefined otherwise.

    Type Parameters

    • S

    Parameters

    • this: readonly defined[]
    • predicate: ((value, index, obj) => value is S)

      find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

        • (value, index, obj): value is S
        • Parameters

          • value: T
          • index: number
          • obj: readonly T[]

          Returns value is S

    Returns undefined | S

  • Returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating no element passed the test.

    Parameters

    • this: readonly defined[]
    • predicate: ((value, index, obj) => undefined | boolean)

      findIndex calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns the index at which it was found. Otherwise, find returns -1.

        • (value, index, obj): undefined | boolean
        • Parameters

          • value: T
          • index: number
          • obj: readonly T[]

          Returns undefined | boolean

    Returns number

  • Performs the specified action for each element in an array.

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => void)

      A function that accepts up to three arguments. forEach calls the callback function one time for each element in the array.

        • (value, index, array): void
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns void

    Returns void

  • Returns whether an array includes a certain element.

    Parameters

    • this: readonly defined[]
    • searchElement: T

      The element to search for.

    • Optional fromIndex: number

      The position in this array at which to begin searching for searchElement.

    Returns boolean

  • Returns the index of the first occurrence of a value in an array, else returns -1.

    Parameters

    • this: readonly defined[]
    • searchElement: T

      The value to locate in the array.

    • Optional fromIndex: number

      The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

    Returns number

  • Returns true if empty, otherwise false.

    Parameters

    • this: readonly any[]

    Returns boolean

  • Adds all the elements of an array separated by the specified separator string.

    Parameters

    • this: readonly defined[]
    • Optional separator: string

      A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

    Returns string

  • Calls a defined callback function on each element of an array, and returns an array that contains the results.

    Type Parameters

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => U)

      A function that accepts up to three arguments. The map method calls the callback function one time for each element in the array.

        • (value, index, array): U
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns U

    Returns U[]

  • Calls a defined callback function on each element of an array, and returns an array that contains the results. Undefined values will not be included, so keep in mind this does not create a 1:1 map.

    Type Parameters

    • U

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => U)

      A function that accepts up to three arguments. The map method calls the callback function one time for each element in the array.

        • (value, index, array): U
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns U

    Returns NonNullable<U>[]

    Example

    // Gets an Array of all existing characters
    const characters = playerlist.mapFiltered(plr => plr.Character);
  • Moves elements to array a2. Returns the destination table a2.

    Parameters

    • this: readonly defined[]
    • f: number

      The beginning of the specified portion of a1.

    • e: number

      The end of the specified portion of a1.

    • t: number

      The beginning of the specified portion of a2.

    • a2: T[]

      The target array.

    Returns T[]

  • Moves elements to array a2. Returns the destination table a2. The destination range can overlap with the source range.

    Parameters

    • this: defined[]
    • f: number

      The beginning of the specified portion of a1.

    • e: number

      The end of the specified portion of a1.

    • t: number

      The beginning of the specified portion of a2.

    • Optional a2: T[]

      The target array, or the current array if unspecified.

    Returns T[]

  • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • this: readonly defined[]
    • callback: ((accumulator, currentValue, currentIndex, array) => T)

      A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the array.

        • (accumulator, currentValue, currentIndex, array): T
        • Parameters

          • accumulator: T
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns T

    Returns T

  • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Type Parameters

    • U

    Parameters

    • this: readonly defined[]
    • callback: ((accumulator, currentValue, currentIndex, array) => U)

      A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the array.

        • (accumulator, currentValue, currentIndex, array): U
        • Parameters

          • accumulator: U
          • currentValue: T
          • currentIndex: number
          • array: readonly T[]

          Returns U

    • initialValue: U

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callback function provides this value as an argument instead of an array value.

    Returns U

  • Gets the length of the array. This is one higher than the highest index defined in an array.

    Returns number

  • Returns whether the specified callback function returns true for any element of an array. Returns false for empty Arrays.

    Parameters

    • this: readonly defined[]
    • callback: ((value, index, array) => undefined | boolean)

      A function that accepts up to three arguments. The some method calls the callback function for each element in array1 until the callback returns true, or until the end of the array.

        • (value, index, array): undefined | boolean
        • Parameters

          • value: T
          • index: number
          • array: readonly T[]

          Returns undefined | boolean

    Returns boolean