Arrays.replaceAll()

Syntax

function replaceAll<T>(array: T[], replacement: Iterable<T>): T[]

Replaces all elements in the array with one or multiple others and returns the original (modified) array.

Parameters
array

An array containing the elements you wish to replace.

element

The element you wish to replace. The array must contain this element.

replacement

The element element should be replaced by.

Example

import { Arrays } from 'potence';

const array = ['foo', 'bar'];

Arrays.replaceAll(array, ['bar', 'baz']);

console.log(array);   // -> ['bar', 'baz']

Remarks

This function modifies the array in-place, i.e. it modifies the original array and returns it. It does not return a new array.

Compare Arrays.replace().