Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including first-match with all npm packages installed. Try it out:

var firstMatch = require("first-match")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

first-match v0.0.1

Find the first element in an array that passes a callback test. Equivalent to underscore.find()

first-match Build Status

Finds the first element in an array that passes a callback test. Equivalent to _.find().

Installation

npm install first-match

Usage

first(array, [iterator], [context]). If an iterator is not passed, the method will just return the first truthy value in the array. The context defaults to the array being evaluated.

var first = require('first-match')
  , array = [0, 1, 2, 3, 4, 5]

first(array)                               // 1
first(array, function(n) { return n > 3 }) // 4
first(array, function(n) { return n % 2 }) // 1
first(array, function(n) { return n + 2 > this.length }) // 5

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free