Skip to content

Replacement for JavaScript's forEach implementation; synchronous & compatible with TypeScript

License

Notifications You must be signed in to change notification settings

ez-libs/ez-each

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Array.ezEach

Build Status npm version
Replacement for JavaScript's forEach implementation; synchronous & compatible with TypeScript

Installation

npm i ez-each

For NPM version < 5

npm install ez-each --save

Usage

Traditional forEach

["a", "b", "c"].forEach((letter: string) => console.log(letter));

Output:

a
b
c

The order of the output is potentially random as it depends on each item's individual iteration time.

Traditional forEach replacement (for loop)

let array = ["a", "b", "c"];
for (let index = 0; index < array.length; index++)
  console.log(array[index]);

Output:

a
b
c

Using ezEach

Import the library just once, at a central place in your code if possible.

import "ez-each"; //or require("ez-each") if you cannot use ES6

["a", "b", "c"].ezEach((letter: string) => console.log(letter));

Output:

a
b
c

Comparison

Function Synchronous Easy Syntax
Array.forEach()
  • no
  • yes
for loop
  • yes
  • no
Array.ezEach()
  • yes
  • yes

About

Replacement for JavaScript's forEach implementation; synchronous & compatible with TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •