Learning JavaScript Data Structures and Algorithms
上QQ阅读APP看书,第一时间看更新

Iterating using forEach

If we need the array to be completely iterated no matter what, we can use the forEach function. It has the same result as using a for loop with the function's code inside it, as follows:

numbers.forEach(x => console.log(x % 2 === 0));