
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Loop over each item in an array and call the given function on every element.
The array-each npm package provides a simple utility for iterating over arrays and executing a function for each element. It is designed to be lightweight and efficient, making it suitable for scenarios where you need to perform operations on each item in an array.
Basic Iteration
This feature allows you to iterate over each element in an array and execute a callback function. The callback receives the current value, the index, and the original array.
const each = require('array-each');
const array = [1, 2, 3, 4];
each(array, function(value, index, array) {
console.log('Value:', value, 'Index:', index);
});
Early Exit
This feature allows you to exit the iteration early by returning `false` from the callback function. This can be useful for performance optimization when you find the element you are looking for.
const each = require('array-each');
const array = [1, 2, 3, 4];
each(array, function(value, index, array) {
if (value === 3) return false; // Exit early
console.log('Value:', value, 'Index:', index);
});
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a `_.forEach` method that offers similar functionality to array-each but with additional features and support for objects as well as arrays.
The async package provides higher-order functions and common patterns for asynchronous code. It includes an `async.each` method that allows for asynchronous iteration over arrays, which is useful for handling I/O-bound operations.
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It includes an `_.each` method that works similarly to array-each but also supports objects.
Loop over each item in an array and call the given function on every element.
npm i array-each --save
var each = require('array-each');
var result = [];
each(['a', 'b', 'c'], function (ele) {
result.push(ele + ele);
});
console.log(result);
//=> ['aa', 'bb', 'cc']
Return false
to "break" early:
var result = [];
each(['a', 'b', 'c'], function (ele) {
if (ele === 'b') return false;
result.push(ele + ele);
});
console.log(result);
//=> ['aa']
Loop over each item in an array and call the given function on every element.
array
{Array}fn
{Function}thisArg
{Object}: Optionally pass a thisArg
to be used as the context in which to call the function.returns
: {Array}each(['a', 'b', 'c'], function (ele) {
return ele + ele;
});
//=> ['aa', 'bb', 'cc']
each(['a', 'b', 'c'], function (ele, i) {
return i + ele;
});
//=> ['0a', '1b', '2c']
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on April 19, 2015.
FAQs
Loop over each item in an array and call the given function on every element.
The npm package array-each receives a total of 2,697,928 weekly downloads. As such, array-each popularity was classified as popular.
We found that array-each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.