Socket
Socket
Sign inDemoInstall

find-replace

Package Overview
Dependencies
1
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    find-replace

Find and either replace or remove items in an array


Version published
Weekly downloads
1.8M
increased by8.39%
Maintainers
1
Install size
22.5 kB
Created
Weekly downloads
 

Readme

Source

view on npm npm module downloads Build Status Dependency Status js-standard-style

find-replace

Find and either replace or remove items in an array.

Example

> const findReplace = require('find-replace')
> const numbers = [ 1, 2, 3]

> findReplace(numbers, n => n === 2, 'two')
[ 1, 'two', 3 ]

> findReplace(numbers, n => n === 2, [ 'two', 'zwei' ])
[ 1, [ 'two', 'zwei' ], 3 ]

> findReplace(numbers, n => n === 2, 'two', 'zwei')
[ 1, 'two', 'zwei', 3 ]

> findReplace(numbers, n => n === 2) // no replacement, so remove
[ 1, 3 ]

findReplace(array, testFn, [...replaceWith]) ⇒ array

Kind: Exported function

ParamTypeDescription
arrayarrayThe input array
testFntestFnA predicate function which, if returning true causes the current item to be operated on.
[...replaceWith]anyIf specified, found values will be replaced with these values, else removed.

© 2015-19 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Keywords

FAQs

Last updated on 22 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc