foreach-array

1.0.1 • Public • Published

foreach-array

This library provides a simple interface to iterate through a given array, avoiding some common errors such as, Uncaught TypeError: parent.children.forEach is not a function. We normally encounter such issues when trying to iterate through an array of DOM elements.

foreach-array will be the solution to such errors. Method signature is similar to Array.prototype.forEach.

Installation

npm i foreach-array

Example Usage

After installing foreach-array module, you can use either import syntax of ES6 or require syntax of node to make this library available in your file.

Using import

import each from 'foreach-array';

const array = ['First Name', 'Last Name', 'Country'];

each(array, (value, index, array) => {
    console.log(index + ': ' + value);
});

// Console log output will be:
//      0: First Name
//      1: Last Name
//      2: Country

Using require

const each = require('foreach-array');

const array = ['First Name', 'Last Name', 'Country'];

each(array, (value, index, array) => {
    console.log(index + ': ' + value);
});

// Console log output will be:
//      0: First Name
//      1: Last Name
//      2: Country

Package Sidebar

Install

npm i foreach-array

Weekly Downloads

2

Version

1.0.1

License

Apache

Unpacked Size

26.4 kB

Total Files

11

Last publish

Collaborators

  • aroshasu