Lodash _.prototype.commit() Method
Last Updated :
03 Nov, 2023
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
}
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...