vanillajs-helpers

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS

View the Project on GitHub Tokimon/vanillajs-helpers

vanillajs-helpers > “indexLoop”

External module: “indexLoop”

Index

Type aliases

Functions


Type aliases

IndexLoopCallback

Τ IndexLoopCallback: function

Defined in indexLoop.ts:5

Type declaration

►(item: any, index: number, arr: ArrayLike.<any>): voidboolean

Parameters:

Param Type Description
item any -
index number -
arr ArrayLike.<any> -

Returns: voidboolean


Functions

indexLoop

indexLoop(collection: any[]⎮ArrayLike.<any>, cb: IndexLoopCallback): number

Defined in indexLoop.ts:25

Iterate over numeric indexes in an object (use return false to break the loop prematurely).

const len = indexLoop([1,2,3], (n) => { console.log(n); }); // -> 1 ... 2 ... 3
// len === 3

// With premature break
indexLoop([1,2,3], (n) => { console.log(n); return n < 3 }); // -> 1 ... 2

Parameters:

Param Type Description
collection any[]⎮ArrayLike.<any> The collection to iterate over
cb IndexLoopCallback The function to call on each iteration

Returns: number