Retrieve the first item in an array that matches a callback function.
Returns null
if a matching element is not found.
File size: 414 bytes.
Supported platforms: server and browser.
Supported language versions: ES3 and above.
If you use this library in your software please tweet me @benastontweet.
npm install find-first
var findFirst = require('find-first');
var arr1 = ['1', '2', '3'];
var arr2 = [1, 2, 3];
function matcher(i) {
return i === '1';
}
findFirst(arr1, matcher); // '1'
findFirst(arr2, matcher); // null
This software is released under the MIT License. It is Copyright 2015, Ben Aston. I may be contacted at ben@bj.ma.
Pull requests including bug fixes, new features and improved test coverage are welcomed. Please do your best, where possible, to follow the style of code found in the existing codebase.