Making your own Javascript Iterator

Making your own Javascript Iterator

Probably many Javascript developers first stumble upon Iterators when looking into the for…of loop. The for…of statement creates a loop and needs an iterable object in order to do so. So what are iterable objects in Javascript? Yeah you guessed it. Arrays is one. We also have some array-like objects such as arguments and NodeLists.

Probably many Javascript developers first stumble upon Iterators when looking into the for…of loop. The for…of statement creates a loop and needs an iterable object in order to do so.

So what are iterable objects in Javascript?

Yeah you guessed it. Arrays is one. We also have some array-like objects such as arguments and NodeLists. Maps, Sets and TypedArrays are also iterable objects. The last honorable mention is the String.

When we iterate these objects an iteration hook with statements are executed for the value of each distinct property of the object.

With this knowledge, could we add a custom iteration hook for a plain Javascript Object which is not iterable by default? A rhetorical question of course.

There is a default iterator available to us in Symbol.iterator.

Lets first see what happens if we remove that from a normal Array.

Image for post

web-development tutorial code javascript programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

FreeCodeCamp JavaScript Tutorial - Learn JavaScript for web development

Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.

JavaScript Game Tutorial | How To Create Snake Game In JavaScript | JavaScript Tutorial

In this Simplilearn's 'JavaScript Game Tutorial' video, we are entirely focusing on the practical application of JavaScript in real-world web applications. We will be building a popular 'Snake' game, that we all have played on our phones, based entirely on JavaScript throughout this video, so brace yourself and start your JavaScript journey!

JavaScript Game Tutorial - Create Tic Tac Toe In JavaScript | JavaScript Tutorial | Simplilearn

In this Simplilearn's 'JavaScript Game Tutorial' video, we are entirely focusing on the practical application of JavaScript in real-world web applications. We will be building a popular game 'Tic-tac-toe' based entirely on JavaScript throughout this video, so brace yourself and start your JavaScript journey!

JavaScript Tutorial: How To Create Your First JavaScript Program

In this JavaScript tutorial for beginners, we will learn how to write your first JavaScript Program, we will follow the below steps: Create a html page, Add JavaScript in the page – Inline, Add JavaScript in the page – External, Check the Developer Console in the browser

FreeCodeCamp JavaScript Tutorial - Learn JavaScript for web development

This video is a javascript tutorial for beginners which I used freecodecamp.com platform as our reference resource. I believe the best way to start programming in 2020 for many people can be this kind of structured platforms like freecodecamp and codecademy. So I think if you want to learn js, watching this video can help.