Function forEachRight

  • Iterates over elements of 'arr' from right to left and invokes 'callback' for each element.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • arr: T[]

      The array to iterate over.

    • callback: ((value: T, index: number, arr: T[]) => void)

      The function invoked per iteration. The callback function receives three arguments:

      • 'value': The current element being processed in the array.
      • 'index': The index of the current element being processed in the array.
      • 'arr': The array 'forEachRight' was called upon.
        • (value, index, arr): void
        • Parameters

          • value: T
          • index: number
          • arr: T[]

          Returns void

    Returns void

    const array = [1, 2, 3];
    const result: number[] = [];

    // Use the forEachRight function to iterate through the array and add each element to the result array.
    forEachRight(array, (value) => {
    result.push(value);
    })

    console.log(result) // Output: [3, 2, 1]
  • Iterates over elements of 'arr' from right to left and invokes 'callback' for each element.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • arr: readonly T[]

      The array to iterate over.

    • callback: ((value: T, index: number, arr: readonly T[]) => void)

      The function invoked per iteration. The callback function receives three arguments:

      • 'value': The current element being processed in the array.
      • 'index': The index of the current element being processed in the array.
      • 'arr': The array 'forEachRight' was called upon.
        • (value, index, arr): void
        • Parameters

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

          Returns void

    Returns void

    const array = [1, 2, 3];
    const result: number[] = [];

    // Use the forEachRight function to iterate through the array and add each element to the result array.
    forEachRight(array, (value) => {
    result.push(value);
    })

    console.log(result) // Output: [3, 2, 1]