Last Updated : 30 Oct, 2023
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
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