VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-each-method/

⇱ Collect.js each() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js each() Method

Last Updated : 14 Apr, 2022

The each() function iterates over the items in the collection and passes each item to a callback. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.


Syntax: 
 

data.each(item)


Parameters: This function accept a single parameter as mentioned above and described below:
 

  • item: This parameter holds the collection item where any operation will be performed on the collection on items.


Return Type: Return a result after performing the define operator operation.Below examples illustrate the each() function in collect.js
Example 1: Here in this example, we take a collection and then using the each() method , we apply + operation to the collection.

Output: 

sum = 10

Example 2:

Output: 

22

Reference: https://collect.js.org/api/each.html

Comment
Article Tags: