Underscore.js _.each() Function
Parameters: It accepts two parameters which are specified below:
- list: It is the list which contains some elements.
- function: It is the function which is executed by taking each element of the list.
Return values: It returns each element of the list.
- Passing a list of numbers with alert() function: When the list of elements is passed to the alert inbuilt function then it takes the element from the list one by one and then shows it on the page (which is the function of the alert function). After alerting all the elements, the alert function ends and the _.each function also ends.
- Passing a list of words with prompt() function: When the list of words is passed to the prompt inbuilt function then it takes the words from the list one by one and then shows it on the page along with its index from the list (which is the function of the prompt function). After alerting all the elements, the prompt function ends and the _.each function also ends.
- Passing a list of numbers with a user defined function: First we need to create a function by using the ‘function’ keyword. Then, when we pass the list of elements to the user defined function then it takes the element from the list one by one and print it. After all the elements are passed, the function ends. And the _.each function also ends.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!
Share your thoughts in the comments
Please Login to comment...