Lodash _.prototype[Symbol.iterator]() 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[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:
Javascript
// Requiring lodash library const _ = require('lodash'); Â Â // Creating wrapped variable var 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:
Javascript
// Requiring lodash library const _ = require('lodash'); Â Â // Creating wrapped variable var wrapr = _(['Geeks', 'for', 'Geeks']); Â Â Â // Calling [Symbol.iterator]() method wrapr[Symbol.iterator]() === wrapr; Â Â let obj = Array.from(wrapr); Â Â // Displays output console.log(obj); |
Output:
[ 'Geeks', 'for', 'Geeks' ]
Example 3:
Javascript
// Requiring lodash library const _ = require('lodash'); Â Â // Calling [Symbol.iterator]() method and // comparing it with wrapped value _("Geeks")[Symbol.iterator]() === _("Geeks"); Â Â // Wrapper object let obj = Array.from(_("Geeks")); Â Â // 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!



