4

In JavaScript, I've heard both the terms "iterable" and "enumerable" used on objects and arrays.

So what is the difference?

batman
  • 5,022
  • 11
  • 52
  • 82
  • I think they both mean the same thing. – Virus721 Sep 04 '13 at 12:57
  • 3
    @epascarello, that is a C# specific question. Note how most of the answers there get C# specific. – batman Sep 04 '13 at 13:03
  • @learner They get C# specific at some point, but by that time, your question is already answered. – kapa Sep 04 '13 at 13:05
  • The selected answer is a general definition. *"Iterating means repeating some steps while enumerating means going throug all values in a collection of values."* Iterating a for type of loop. `for(var i=0;i – epascarello Sep 04 '13 at 13:06
  • 1
    @learner: The principle idea behind iteration when compared to enumeration should not change though. The accepted answer on the C# question still would apply I think. – Nope Sep 04 '13 at 13:08
  • 1
    I'd reopen the question, but... I'll just answer in comment. Iterable (possibly) should mean entity, which could be iterated on ([see also](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)), it refers to collection. It is not mentioned in standard, though. Enumerable means property of object, on which iteration is performed. And it means property, an item of collection ([es-5.1](http://www.ecma-international.org/ecma-262/5.1/)) – kirilloid Sep 04 '13 at 13:08
  • reopen for what? OP got clear explanation in the above comments. right? – Mr_Green Sep 04 '13 at 13:10
  • Thinking in terms of interfaces, to me *enumerable* means you can tell how many items the collection has. Meanwhile *iterable* means you can repeat the same action on the elements of a collection, but you do not necessarily know how many there are. But I might be wrong. – kapa Sep 04 '13 at 13:11
  • Reopen, beacuse this should not be closed (at least) as duplicate to question in C#. – kirilloid Sep 04 '13 at 13:20
  • Reopen. Anyway...Enumerable is a property with `propertyIsEnumerable` set to `true` [mozilla doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties). You iterate over enumerable properties using `for ... in`. Iterable is a protocol; you loop over an iterable using `for ... of`. You make an object iterable by implementing `@@iterator` [mozilla doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) – slushy Jan 09 '19 at 03:42

0 Answers0