Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptLodash _.juxt() Method

Lodash _.juxt() Method

The Lodash _.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 accepts n functions containing the logic to return values.

Return Value: This method returns a function.

Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.

npm install lodash-contrib

Below examples illustrate the Lodash _.juxt() method in JavaScript:

Example 1:

Javascript




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


Output:

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

Example 2: 

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib');
 
function a() {
    return "a";
}
function b() {
    return "b";
}
function c() {
    return "c";
}
function d() {
    return "d";
}
 
 
// Defining function
var abcd = _.juxt( a, b, c, d );
 
console.log(abcd());


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!

RELATED ARTICLES

Most Popular

Recent Comments