array-replace

1.0.1 • Public • Published

array-replace Build Status

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');
//=> ['yo', 'bar']
 
arrayReplace(arr, 'fo', str => str.toUpperCase());
//=> ['FOo', 'bar']

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

Package Sidebar

Install

npm i array-replace

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • gillstrom