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]() method.
Javascript
// Requiring lodash library const _ = require( 'lodash' ); // Creating wrapped variable let wrapr = _([8, 9]); // Calling [Symbol.iterator]() method wrapr[Symbol.iterator]() === wrapr; let obj = Array.from(wrapr); // Displays output console.log(obj); |
Output:
[ 8, 9 ]
Example 2: In this example, we are using the lodash _.prototype[Symbol.iterator]() method.
Javascript
// Requiring lodash library const _ = require( 'lodash' ); // Creating wrapped variable let wrapr = _([ 'Beginner' , 'for' , 'Beginner' ]); // Calling [Symbol.iterator]() method wrapr[Symbol.iterator]() === wrapr; let obj = Array.from(wrapr); // Displays output console.log(obj); |
Output:
[ 'Beginner', 'for', 'Beginner' ]
Example 3: In this example, we are using the lodash _.prototype[Symbol.iterator]() method.
Javascript
// Requiring lodash library const _ = require( 'lodash' ); // Calling [Symbol.iterator]() method and // comparing it with wrapped value _( "Beginner" )[Symbol.iterator]() === _( "Beginner" ); // Wrapper object let obj = Array.from(_( "Beginner" )); // Displays output console.log(obj[0]); console.log(obj[1]); console.log(obj[2]); console.log(obj[3]); |
Output:
G
e
e
k
Reference: https://lodash.com/docs/4.17.15#prototype-Symbol-iterator
Contact Us