Open In App

Lodash _.flip() Method

Last Updated : 03 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Lodash _.flip() method is used to create a function that invokes the given func parameter with its arguments reversed.

Syntax:

_.flip( func );

Parameters:

  • func: This parameter holds the function that takes some arguments.

Return Value:

  • This method returns the new flipped function.

Example 1: In this example, we are flipping the given values and putting them in an array then printing it into the console.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

function Func(a, b) {
    return b + " is " + a;
}

// Using the _.flip() method  
let gfg = _.flip(Func);

console.log(
    gfg("GeeksforGeeks",
        "A Computer Science Portal for Geeks")
);

Output:

"GeeksforGeeks is A Computer Science Portal for Geeks"

Example 2: In this example, we are flipping the given values and putting them in an array then printing it into the console.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Using the _.flip() method 
let flipped = _.flip(function () {
    return _.toArray(arguments);
});

console.log(
    flipped('c', 'cpp', 'java', 'python')
);

Output:

['python', 'java', 'cpp', 'c']

Similar Reads