Lodash - uniqueId 方法
语法
_.uniqueId([prefix=''])
生成唯一 ID。如果指定了前缀,则将 ID 附加到前缀。
参数
[prefix=''] (string) − 为 ID 加上前缀的值。
输出
(string) − 返回唯一 ID。
示例
var _ = require('lodash'); console.log(_.uniqueId('id_')); console.log(_.uniqueId());
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
id_1 2