mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
ba1e976c5a
* feat(forEachRight): Add forEachRight function * feat(forEachRight): Add forEachRight test code * feat(forEachRight): Add forEachRight function bench * feat(forEachRight): Add forEachRight function docs * Update docs/ko/reference/array/forEachRight.md * Update docs/reference/array/forEachRight.md --------- Co-authored-by: Sojin Park <raon0211@gmail.com> Co-authored-by: Sojin Park <raon0211@toss.im>
943 B
943 B
forEachRight
Iterates over elements of arr
from right to left and invokes callback
for each element.
Signature
function forEachRight<T>(arr: T[], callback: (value: T, index: number, arr: T[]) => void): void;
Parameters
arr
(T[]
): The array to iterate over.callback
((value: T, index: number, arr: T[])
): The function invoked per iteration.value
: The current element being processed in the array.index
: The index of the current element being processed in the array.arr
: The arrayforEachRight
was called upon.
Returns
void
Examples
import { forEachRight } from 'es-toolkit/forEachRight';
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];