---
title: "Discussion on \"JS for..of and for..in\" | Hashnode"
description: "Discussion on \"JS for..of and for..in\". When to use for..of and for..in in Javascript?\nLooping through Arrays and Objects\nBy definition, the main difference between for..of and for..in is on where each of them looks as they loop through an array or object. As explained on Stackoverflow by ..."
url: "https://hashnode.com/posts/js-for-of-vs-for-in/5f6391b8db767922c472e27a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [JS for..of and for..in](https://gabslach.hashnode.dev/js-for-of-vs-for-in?utm_source=hashnode&utm_medium=feed)

When to use for..of and for..in in Javascript? Looping through Arrays and Objects By definition, the main difference between for..of and for..in is on where each of them looks as they loop through an array or object. As explained on Stackoverflow by ...

Sep 17, 2020 · 3 min read · gabslach.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[drxlopez](https://hashnode.com/@gabslach)

@gabslach

  
[View profile](https://hashnode.com/@gabslach)

Sleep. Code. Repeat.

## Responses 2

Markdown supported · ⌘↵ to post

[Dinys Monvoisin](https://hashnode.com/@dinmon)

[Sep 18, 2020](https://hashnode.com/posts/js-for-of-vs-for-in/5f6391b8db767922c472e27a/comment/5f645e3ca2a2fb2455127984)

Would not it better off saying that `for...of` is used with array type values only rather than saying it generates an error message?

[drxlopez](https://hashnode.com/@gabslach)

[Sep 18, 2020](https://hashnode.com/posts/js-for-of-vs-for-in/5f6391b8db767922c472e27a/comment/5f645e3ca2a2fb2455127984#reply-5f648dfe96b4a436fe135e9c)

Good point, I only chose to describe it that way to emphasize it haha.

[Dinys Monvoisin](https://hashnode.com/@dinmon)

[Sep 18, 2020](https://hashnode.com/posts/js-for-of-vs-for-in/5f6391b8db767922c472e27a/comment/5f645e3ca2a2fb2455127984#reply-5f64981996b4a436fe135f0b)

It make it confusing and imagine someone who is starting.

[drxlopez](https://hashnode.com/@gabslach)

[Sep 17, 2020](https://hashnode.com/posts/js-for-of-vs-for-in/5f6391b8db767922c472e27a/comment/5f63921492571222a319d3ba)

I want to hear what you think, I will appreciate your comments :)
