Skip to content

replace

Replace the first occurrence of an item in an array where the `match` function returns true. If no items match, append the new item to the end of the list if append is `true`.

Usage

replace([1, 2, 3], 4, (n) => n > 1); // [1, 4, 3]
replace([1, 2, 3], 4, (n) => n > 100); // [1, 2, 3, 4]

Installation

Terminal window
npx atmx add helper replace