Friday, September 5, 2025
HomeLanguagesJavascriptUnderscore.js _.unsplatl() Method

Underscore.js _.unsplatl() Method

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




// Defining underscore contrib variable
var _ = require("underscore-contrib");
  
// Function that takes array as the
// first parameter
function g(arr, val) {
  return val + " : " + arr;
}
  
// Using the unsplatl() method
var gfgFunc = _.unsplatl(g);
  
console.log(gfgFunc(1, 2, 3, 4, "A"));


Output:

A : 1,2,3,4

Example 2: 

Javascript




// Defining underscore contrib variable
var _ = require("underscore-contrib");
  
// Function that takes array as the
// first parameter
function g(arr) {
  return arr;
}
  
// Using the unsplatl() method
var gfgFunc = _.unsplatl(g);
  
console.log(gfgFunc(1, 2, 3, 4));


Output:

[ 1, 2, 3, 4 ]

Example 3: 

Javascript




// Defining underscore contrib variable
var _ = require("underscore-contrib");
  
// Function that takes array as the
// first parameter
function g(arr, val) {
  return arr.join(val);
}
  
// Using the unsplatl() method
var gfgFunc = _.unsplatl(g);
  
console.log(
  gfgFunc("neveropen"
  "Computer Science Portal for Geeks", " : ")
);


Output:

neveropen : Computer Science Portal for Geeks
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS