JavaScript · Junior · Question 25 of 75

How does for...in differ from for...of?

Explanation

for (const key in obj) goes over enumerable string keys, including inherited ones. for (const item of arr) works with iterables: arrays, strings, Map, Set. for...in isn't suitable for arrays - it yields indexes as strings.

Further reading

Problem with a question

JavaScript · Junior · question 25

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz