Underscore.JS - iteratee method



Syntax

_.iteratee(value, [context])

iteratee method helps to create a callback function which can be called on each element of a collection. See the below example −

Example

var _ = require('underscore');
var list = [1, 2, 3, 4, 5];

var square = _.iteratee(function(n){console.log(n*n);});

list.forEach(square);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

1
4
9
16
25
underscorejs_utilities.htm
Advertisements