Basic usage

Given an array of items, replace the one that matches the given condition function. Only replaces the first match. Always returns a copy of the original array.

import { replace } from 'radash'

const fish = [{
  name: 'Marlin',
  weight: 105
}, {
  name: 'Bass',
  weight: 8
}, {
  name: 'Trout',
  weight: 13

const salmon = {
  name: 'Salmon',
  weight: 22

// read: replace fish with salmon where the name is Bass
replace(fish, salmon, f => === 'Bass') // => [marlin, salmon, trout]


This _.replace function is 100% covered by tests. See them and contribute at GitHub.


See the source for _.replace on GitHub.