New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

or

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

or

Returns an element from an array when it matches a condition

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-6.49%
Maintainers
1
Weekly downloads
 
Created
Source

Returns the element of an array when the callback returns true.

Purpose

This module provides a similar function as Array.prototype.filter, but it returns the element, not an array. And it stops looping as soon as it finds a result.

Usage

var arr = ['item', 'other', 'finally'];

var item = or(arr, function(item) {
    return item === 'other';
});

console.log(item); // "other"

// Real world example
var matchesSelector = or(['matchesSelector', 'mozMatchesSelector',
    'webkitMatchesSelector', 'oMatchesSelector',
    'msMatchesSelector'], function(shim) {
    return shim in document.documentElement;
});

document.getElementById('some')[matchesSelector]('#some'); // true

API

The module returns a function accepting the following arguments:

  • array: the array on which to iterate
  • callback: the function being called
  • context: the context on which to call the callback

Contributors

  • Florian Margaine

License

MIT License.

Keywords

FAQs

Package last updated on 27 Feb 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc