HTML CHEAT SHEET

Array Higher Order Functions

.forEach()

.forEach() iterates through each element executing a provided function for each element.


const array = ["jack", "and", "jill", "went", "up", "the", "hill"];

function displayString(str){
    console.log(str);
}

array.forEach(displayString);

Output:


jack
and
jill
went
up
the
hill

You can use an anonymous function (most common) as well


const array = ["jack", "and", "jill", "went", "up", "the", "hill"];

array.forEach((element) => { console.log(element); });

Did you know?

The first version of HTML was written by Tim Berners-Lee in 1993. Since then, there have been many different versions of HTML. The most widely used version throughout the 2000's was HTML 4.01, which became an official standard in December 1999. Another version, XHTML, was a rewrite of HTML as an XML language.