Open In App

Lodash _.prototype.next() Method

Last Updated : 30 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.prototype.next() method of Sequence in lodash is used to find the next value on a wrapped object which follows the iterator protocol.

Syntax:

_.prototype.next();

Return Value:

This method returns the value of the next iterator.

Example 1: In this example, it returns the next value of the wrapper by the use of the lodash _.prototype.next() method.

Javascript




// Requiring lodash library
const _ = require('lodash');
 
// Initializing wrapped value
let wrapper = _([5, 6]);
 
// Calling prototype.next() method
let res1 = wrapper.next();
let res2 = wrapper.next();
 
// Displays output
console.log(res1);
console.log(res2);


Output:

{ done: false, value: 5 }
{ done: false, value: 6 }

Example 2: In this example, the output is ‘undefined’ as there is no value to print.

Javascript




// Requiring lodash library
const _ = require('lodash');
 
// Initializing wrapped value
let wrapper = _([]);
 
// Calling prototype.next() method
let result = wrapper.next();
 
// Displays output
console.log(result);


Output:

{ done: true, value: undefined }

Example 3: In this example, only the defined value is returned to the output.

Javascript




// Requiring lodash library
const _ = require('lodash');
 
// Calling prototype.next() method
let result1 = _({ 'f': 5 }).next();
let result2 = _({ 'g': (1 / 0) }).next();
 
// Displays output
console.log(result1);
console.log(result2);


Output:

{ done: false, value: 5 }
{ done: false, value: Infinity }

Reference: https://lodash.com/docs/4.17.15#prototype-next



Previous Article
Next Article

Similar Reads

Lodash _.prototype.toJSON() Method
The _.prototype.toJSON() method of Sequence in lodash is used to execute the chain sequence in order to solve the unwrapped value. Syntax: _.prototype.toJSON() Parameters: This method doesn't accept any parameter. Return Value: This method returns the resolved unwrapped value. Below examples illustrate the Lodash _.prototype.toJSON() method in Java
1 min read
Lodash _.prototype.valueOf() Method
The _.prototype.valueOf() method of Sequence in lodash is used to execute the chain sequence in order to solve the unwrapped value. Syntax: _.prototype.valueOf() Parameters: This method doesn't accept any parameter. Return Value: This method returns the resolved unwrapped value. Below examples illustrate the Lodash _.prototype.valueOf() method in J
1 min read
Lodash _.prototype.at() Method
Lodash _.prototype.at([paths]) method of Sequence in lodash is the wrapper version of the _.at() method which creates an array of values analogous to the specified paths of an object. Syntax:_.prototype.at([paths]);Parameters:[paths]: It is the paths property that is to be chosen.Return Value: This method returns the new lodash wrapper instance. Ex
1 min read
Lodash _.prototype.reverse() Method
Lodash _.prototype.reverse() method of Sequence in lodash is used to mutate the wrapped array. Moreover, it is the wrapper version of the _.reverse method of an array. Syntax:_.prototype.reverse();Parameters: This method doesn't accept any parameter. Return Value: This method returns the new lodash wrapper instance. Example 1: In this example, we a
1 min read
Lodash _.prototype.plant() Method
Lodash _.prototype.plant(value) method of Sequence in lodash is used to create a clone of the chain sequence type by planting the value to be planted as the wrapped value. Syntax:_.prototype.plant(value);Parameters: value: It is the value that needs to be planted.Return Value: This method returns the new lodash wrapper instance. Example 1: In this
1 min read
Lodash _.prototype[Symbol.iterator]() Method
Lodash _.prototype[Symbol.iterator]() method of Sequence in lodash is used to permit the wrapper to be iterable. Syntax:_.prototype[Symbol.iterator]();Parameters: This method doesn't accept any parameter. Return Value: This method returns the lodash wrapper object. Example 1: In this example, we are using the lodash _.prototype[Symbol.iterator]() m
1 min read
Lodash _.prototype.chain() Method
Lodash _.prototype.chain() method of Sequence in lodash is used to create an instance of lodash wrapper accompanied by explicit method chain sequences enabled. Syntax:_.prototype.chain();Parameters: This method doesn't accept any parameter. Return Value: This method returns the new lodash wrapper instance. Example 1: In this example, we are chainin
2 min read
Lodash _.prototype.commit() Method
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
2 min read
Lodash _.prototype.value() Method
Lodash _.prototype.value() method is used to execute the given chain sequence in order to resolve the unwrapped value. This method has the aliases _.prototype.toJSON and _.prototype.valueOf. Syntax:_.prototype.value()Parameters: This method does not accept any parameter. Return Value: This method returns the resolved unwrapped value. Example 1: In
1 min read
Difference between Function.prototype.apply and Function.prototype.call
JavaScript treats everything as an object, even functions, and every object has its own properties and methods. Function objects have both apply() and call() methods on them. However, there is confusion about the two functions in JavaScript. The main difference between them is how they handle function arguments. There is no difference between these
2 min read