Lodash _.flip() Method
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( "w3wiki" , "A Computer Science Portal for Beginner" ) ); |
Output:
"w3wiki is A Computer Science Portal for Beginner"
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']
Contact Us