Socket
Socket
Sign inDemoInstall

foreach

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

foreach

foreach component + npm package


Version published
Maintainers
1
Weekly downloads
2,285,119
decreased by-5.82%

Weekly downloads

Package description

What is foreach?

The 'foreach' npm package provides a utility for iterating over arrays and objects in a concise and consistent manner. It allows developers to execute a function for each element in an array or each property in an object, similar to the native forEach method available on arrays in JavaScript.

What are foreach's main functionalities?

Iterating over arrays

This feature allows you to iterate over each item in an array and execute a function that has access to the item value, index, and the original array.

foreach([1, 2, 3], function(value, index, array) {
  console.log(value);
});

Iterating over object properties

This feature allows you to iterate over each key-value pair in an object and execute a function that has access to the value, key, and the original object.

foreach({ a: 1, b: 2, c: 3 }, function(value, key, object) {
  console.log(key + ': ' + value);
});

Other packages similar to foreach

Readme

Source

foreach

CDNJS

Iterate over the key value pairs of either an array-like object or a dictionary like object.

browser support

API

foreach(object, function, [context])

var each = require('foreach');

each([1,2,3], function (value, key, array) {
    // value === 1, 2, 3
    // key === 0, 1, 2
    // array === [1, 2, 3]
});

each({0:1,1:2,2:3}, function (value, key, object) {
    // value === 1, 2, 3
    // key === 0, 1, 2
    // object === {0:1,1:2,2:3}
});

Keywords

FAQs

Last updated on 11 May 2022

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