array-replace
Replace array values with String.prototype.replace
Install
$ npm install --save array-replace
Usage
const arrayReplace = require('array-replace');
const arr = [
'foo',
'bar'
];
arrayReplace(arr, 'fo', 'y');
arrayReplace(arr, 'fo', str => str.toUpperCase());
API
arrayReplace(input, search, replace)
Returns a new array.
input
Required
Type: array
The array to replace values in.
search
Required
Type: string
or regexp
Search for matching substring that will be replaced.
replace
Required
Type: string
or function
Replacing the matching substring.
Related
- key-replace - Replace object keys with
String.prototype.replace
License
MIT © Andreas Gillström