Saturday, October 25, 2025
HomeLanguagesJavascriptLodash _.prototype.commit() Method

Lodash _.prototype.commit() Method

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

The _.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:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Creating an array of integers
var arr = [5, 6];
  
// Pushing an integer into the array
var wrapper = _(arr).push(7);
   
// Using the commit() method
wrapper = wrapper.commit();
  
// Displays output
console.log(arr);


Output:

[ 5, 6, 7 ]

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Creating an array of strings
var arr = ['Geeks', 'for'];
  
// Pushing a string into the array
var 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
obj = _(['G', 'f']).reverse().commit();
  
// Displays output
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, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS