- Underscore.JS - Home
- Underscore.JS - Overview
- Underscore.JS - Environment Setup
- Underscore.JS - Iterating Collection
- Underscore.JS - Processing Collection
- Underscore.JS - Iterating Array
- Underscore.JS - Processing Array
- Underscore.JS - Functions
- Underscore.JS - Mapping Objects
- Underscore.JS - Updating Objects
- Underscore.JS - Comparing Objects
- Underscore.JS - Utilities
- Underscore.JS - Chaining
- Underscore.JS Useful Resources
- Underscore.JS - Quick Guide
- Underscore.JS - Useful Resources
- Underscore.JS - Discussion
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