Underscore.JS - uniqueId method



Syntax

_.uniqueId([prefix])

uniqueId method generates a unique id as name suggests. If prefix is passed then prefix is appended to that id. See the below example:

Example

var _ = require('underscore');

// Example 1
var uniqueId1 = _.uniqueId("text");
// Example 2
var uniqueId2 = _.uniqueId("text");

console.log(uniqueId1);
console.log(uniqueId2);

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