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 > “eachWord”

External module: “eachWord”

Index

Functions


Functions

eachWord

eachWord(phrase: string, cb: IndexLoopCallback, separator?: RegExpstring): number

Defined in eachWord.ts:27

Iterate over each word in a phrase (or return word count if no callback is given)

// Default seperator
const count = eachWord('Hello JS-World', word => console.log(word));
// Hello ... JS ... World
// count === 3

// With specified separator
const count = eachWord('Hello JS World-Championship', word => console.log(word), ' ');
// Hello ... JS-World
// count === 2

Parameters:

Param Type Default value Description
phrase string - Phrase to loop over
cb IndexLoopCallback - Callback function to call on every iteration
separator RegExpstring /[- _,]+/ -

Returns: number