forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterable.jsdoc
More file actions
34 lines (26 loc) · 841 Bytes
/
iterable.jsdoc
File metadata and controls
34 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Iterable : Object
An iterable object is any object that returns a function that produces
an %%/Iterator|Iterator%% for its %%/Symbol#iterator|**Symbol.iterator**%%
property.
You can loop over all values in an iterable object by using a
**for (var value of iterable) { }** loop.
See %%/Iterator|Iterator%% for more details.
<example>
// Arrays are a built in Iterable object
var arr = ['a', 'b', 'c'];
// Use for (... of ...) loop to get the values of an iterable
for (var x of arr) {
console.log(x);
}
// Under the covers, for (... of ...) does the following:
var iterator = arr[Symbol.iterator]();
var current = iterator.next();
while (!current.done) {
console.log(current.value);
current = iterator.next();
}
</example>
Version:
ECMAScript 2015
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-iterable-interface