Lodash _.prototype.commit() method is used to implement the chain sequence type and find the wrapped output.
Syntax:
_.prototype.commit();
Parameters:
This method does not accept any parameter.
Return Value:
This method returns the new lodash wrapper instance.
Example 1: In this example, we are pushing an element into a given array and committing the array with the help of the lodash _.prototype.commit() method.
Javascript
const _ = require( 'lodash' );
let arr = [5, 6];
let wrapper = _(arr).push(7);
wrapper = wrapper.commit();
console.log(arr);
|
Output:
[ 5, 6, 7 ]
Example 2: In this example, we are pushing an element into a given array and committing the array with the help of the lodash _.prototype.commit() method.
Javascript
const _ = require( 'lodash' );
let arr = [ 'Geeks' , 'for' ];
let wrapper = _(arr).push( 'Geeks' );
wrapper = wrapper.commit();
console.log(arr);
|
Output:
[ 'Geeks', 'for', 'Geeks' ]
Example 3: In this example, the wrapper object is returned.
Javascript
const _ = require( 'lodash' );
let obj = _([ 'G' , 'f' ]).reverse().commit();
console.log(obj);
|
Output:
LodashWrapper {
__wrapped__: [ 'f', 'G' ],
__actions__: [],
__chain__: false,
__index__: 0,
__values__: undefined
}
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!