for-each
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
is-callable | 1.2.7 | 9.66 kB | MIT | prod |
"For-each" is an npm package that augments the functionality of JavaScript's traditional Array.prototype.forEach method. It not only works well on traditional arrays but also shines when used on objects, something Array.prototype.forEach cannot inherently do. This makes it an invaluable tool for developers looking for a reliable way to iterate over data stored in JavaScript Objects.
To use "for-each", you will first need to install it via NPM using the command npm install for-each
. After it's installed, you can require it in your JavaScript file and then use it to iterate over both arrays and objects. Below are two examples:
var forEach = require("for-each")
forEach({ key: "value" }, function (value, key, object) {
/* code */
})
You see here how "for-each" can be used on a JavaScript object. The function accepts two arguments - the object and a callback. The callback in turn receives three arguments - the value of the current property, the key of the current property, and the original object.
var forEach = require("for-each")
forEach([1, 2, 3], function (value, index, array) {
/* code */
})
In this example, "for-each" is used like the traditional forEach method on an array. Here, the function accepts an array and a callback. The callback receives the value of the current element, the index of the current element, and the original array.
The documentation for "for-each" can be found on its GitHub page (https://github.com/Raynos/for-each.git). The README file there contains all the necessary information about its capabilities, installation process, and usage along with code examples.