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
// Requiring lodash library
const _ = require('lodash');
// Creating an array of integers
let arr = [5, 6];
// Pushing an integer into the array
let wrapper = _(arr).push(7);
// Using the commit() method
wrapper = wrapper.commit();
// Displays output
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
// Requiring lodash library
const _ = require('lodash');
// Creating an array of strings
let arr = ['Geeks', 'for'];
// Pushing a string into the array
let wrapper = _(arr).push('Geeks');
// Using the commit() method
wrapper = wrapper.commit();
// Displays output
console.log(arr);
Output:
[ 'Geeks', 'for', 'Geeks' ]
Example 3: In this example, the wrapper object is returned.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Using the commit() method
let obj = _(['G', 'f']).reverse().commit();
// Displays output
console.log(obj);
Output:
LodashWrapper { __wrapped__: [ 'f', 'G' ], __actions__: [], __chain__: false, __index__: 0, __values__: undefined }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4