![]() |
VOOZH | about |
Lodash _.forEach() method iterates over elements of the collection and invokes iterate for each element.
_.forEach(collection, [iteratee = _.identity]);This method returns the collection.
Example 1: In this example, we are iterating an array by the use of the _.forEach() method and printing the results in the console.
Output:
'c'
'cpp'
'java'
'python'
Example 2: In this example, we are iterating an object by the use of the _.forEach() method and printing the results in the console.
Output:
'x'
'y'
Note: This will not work in normal JavaScript because it requires the library lodash to be installed.