Saturday, August 30, 2025
HomeLanguagesJavascriptUnderscore.js _.juxt() Method

Underscore.js _.juxt() Method

The _.juxt() method returns a function whose return value is an array of the results after calling each of the functions with the given arguments.

Syntax:

_.juxt( function1, function2, .., function );

Parameters: This method takes n functions containing the logic to return values.

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.

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1: In this example, we will see the use of the _.juxt() method

javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
 
function firstG(val) {
    return val[0];
}
function F(val) {
    return val[5];
}
function lastG(val) {
    return val[8];
}
 
// Defining function
let firstAndLastChars = _.juxt(firstG, F, lastG);
 
console.log(firstAndLastChars("neveropen"));


Output:

[ 'G', 'f', 'G' ]

Example 2: In this example, we will see the use of the _.juxt() method

javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
 
function a() {
    return "a";
}
function b() {
    return "b";
}
function c() {
    return "c";
}
function d() {
    return "d";
}
 
 
// Defining function
let firstAndLastChars = _.juxt(a, b, c, d);
 
console.log(firstAndLastChars("neveropen"));


Output:

[ 'a', 'b', 'c', 'd' ]
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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS