Member-only story

Demystifying Iterables by implementing a python like range function

Vivek Nayyar
5 min readMay 26, 2021

Photo by Rich Tervet on Unsplash

With ES6, we got introduced to the concept of Iterables. Iterating over an array using a for-in loop or a for-of loop is not new to us.

We have all done something like this at least once in our codebase:

But what if you would want to have that same functionality of iterating over something that is not an Array. How about an object?

In order to iterate over its values, we might have to use Object.values with a map.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Vivek Nayyar
Vivek Nayyar

Written by Vivek Nayyar

Engineering Manager and Board game enthusiast

Responses (1)

Write a response

Python's `range()` function does not return an array (list in Python-speak), but a range object - which isn't an iterator, either, but rather a special immutable sequence type. The difference is that unlike an array, it doesn't store its elements…

--