@writetome51/array-replace-first-of-all-of
v2.0.0
Published
Functions that replace particular values found in array with new values
Downloads
6
Maintainers
Readme
replaceFirstOf( value, newValue, array): void
Replaces first instance of value
with newValue
in array
.
replaceAllOf( value, newValue, array): void
Replaces all instances of value
with newValue
in array
.
NOTICE : For both functions, any parameter called value
cannot be an
object. It can be an array, as long as the array does not contain an object.
Installation
npm i @writetome51/array-replace-first-of-all-of
Examples
let arr = [1,2,3,1,2,3,1,2,3];
replaceFirstOf(2, 20, arr);
// arr is now [1,20,3,1,2,3,1,2,3]
let arr = [1,2,3,1,2,3,1,2,3];
replaceAllOf(2, 20, arr);
// arr is now [1,20,3,1,20,3,1,20,3]
Loading
// if using TypeScript:
import { replaceFirstOf, replaceAllOf }
from '@writetome51/array-replace-first-of-all-of';
// if using ES5 JavaScript:
var replaceFirstOf =
require('@writetome51/array-replace-first-of-all-of').replaceFirstOf;
var replaceAllOf =
require('@writetome51/array-replace-first-of-all-of').replaceAllOf;