`_.each` function on array using JavaScript Library underscore.js ( #shorts )

1 year ago
1

Hi Friends,

`_.each` function on array using JavaScript Library underscore.js

`_.each` is a utility function in Underscore.js library that allows you to iterate over elements in a collection (an array or an object). It provides a way to perform a specified operation or execute a callback function for each element in the collection.

In below example, we have an array of numbers numbers. We use _.each to iterate over each element in the array. For each element, the provided anonymous function is executed, which simply logs the number to the console. As a result, each number in the array will be printed to the console.

Note: _.each can also be used with objects

// syntax
_.each(collection, iteratee)

// example
var numbers = [1, 2, 3, 4, 5];

_.each(numbers, function(number) {
console.log(number);
});
// 1, 2, 3, 4, 5

#javascript #under #score #underscore #underscorejs #each #underscoreeach #eachfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official

Loading comments...