DEV Community

Discussion on: Problems with Using for...in on Arrays in JavaScript

Collapse
 
lionelrowe profile image
lionel-rowe

It's a little different from Object.keys and so on. You can do Object.keys(arr) too, but then you'll get an array of string keys, rather than an iterator of number keys. Interestingly, there's no such thing as Object#keys — I guess it doesn't make sense to return an iterator of keys for something that itself isn't iterable.

Thread Thread
 
imjoshellis profile image
Josh Ellis

Right, because they're class methods on Object that take a param, that's probably why I didn't think to look into how it could work with arrays. Very interesting.