Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.flip() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

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

Syntax:

_.flip( func )

Parameters: This method accepts a single parameter as mentioned above and described below:

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

Return Value: This method return the new flipped function.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
   
function Func(a, b) { 
    return b + " is " + a;
   
// Using the _.flip() method  
var gfg = _.flip(Func); 
     
console.log(
  gfg("GeeksforGeeks",
      "A Computer Science Portal for Geeks")
);

Output:

"GeeksforGeeks is A Computer Science Portal for Geeks"

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Using the _.flip() method 
var flipped = _.flip(function() {
  return _.toArray(arguments);
});
  
console.log(
  flipped('c', 'cpp', 'java', 'python')
);

Output:

['python', 'java', 'cpp', 'c']
My Personal Notes arrow_drop_up
Last Updated : 13 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials