Lodash - nthArg 方法

语法

_.nthArg([n=0])

创建一个获取索引 n 处的参数的函数。如果 n 为负数,则返回从末尾开始的第 n 个参数。

参数

  • [n=0] (number) − 要返回的参数的索引。

输出

  • (Function) − 返回新的 pass-thru 函数。

示例

var _ = require('lodash');
var func = _.nthArg(1);
console.log(func('a', 'b', 'c', 'd'));

func = _.nthArg(2);
console.log(func('a', 'b', 'c', 'd'));

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

b
c

lodash_util.html