Underscore.js _.unsplatl() Method
Last Updated :
23 Aug, 2020
The _.unsplatl() method takes a function expecting an array as its first argument and returns a function which works identically, but takes list of leading arguments. It is similar to the unsplat() method. It mimics the rest parameter syntax in ECMAScript 6.
Syntax:
_.unsplatl( function )
Parameters:
- function: It is the original function that takes its first argument as an array.
Return Value: This method returns a function.
Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. The Underscore.js contrib library can be installed using npm install underscore-contrib –save.
Example 1:
Javascript
var _ = require( "underscore-contrib" );
function g(arr, val) {
return val + " : " + arr;
}
var gfgFunc = _.unsplatl(g);
console.log(gfgFunc(1, 2, 3, 4, "A" ));
|
Output:
A : 1,2,3,4
Example 2:
Javascript
var _ = require( "underscore-contrib" );
function g(arr) {
return arr;
}
var gfgFunc = _.unsplatl(g);
console.log(gfgFunc(1, 2, 3, 4));
|
Output:
[ 1, 2, 3, 4 ]
Example 3:
Javascript
var _ = require( "underscore-contrib" );
function g(arr, val) {
return arr.join(val);
}
var gfgFunc = _.unsplatl(g);
console.log(
gfgFunc( "GeeksforGeeks" ,
"Computer Science Portal for Geeks" , " : " )
);
|
Output:
GeeksforGeeks : Computer Science Portal for Geeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...