summaryrefslogtreecommitdiffhomepage
path: root/typescript.html.markdown
diff options
context:
space:
mode:
authorashraf-patel <ashrafp725@gmail.com>2019-06-17 14:52:58 +0530
committerashraf-patel <ashrafp725@gmail.com>2019-06-17 14:52:58 +0530
commit145e76d3b318eab8ff78980c57f34e622a1988b2 (patch)
tree1645bbf712790c4128e4d27052c73d2390fe5842 /typescript.html.markdown
parent592901be9ce3bd6c854bbd1f0fa29981d373cec6 (diff)
Iterators and Generators
Diffstat (limited to 'typescript.html.markdown')
-rw-r--r--typescript.html.markdown19
1 files changed, 19 insertions, 0 deletions
diff --git a/typescript.html.markdown b/typescript.html.markdown
index ba4a9e71..9f0f4c6d 100644
--- a/typescript.html.markdown
+++ b/typescript.html.markdown
@@ -223,6 +223,25 @@ moreNumbers[5] = 5; // Error, elements are read-only
moreNumbers.push(5); // Error, no push method (because it mutates array)
moreNumbers.length = 3; // Error, length is read-only
numbers = moreNumbers; // Error, mutating methods are missing
+
+// Iterators and Generators
+
+// for..of statement
+// iterate over the list of values on the object being iterated
+let list = [4, 5, 6];
+for (let i of list) {
+ console.log(i); // "4", "5", "6"
+}
+
+// for..in statement
+// iterate over the list of keys on the object being iterated
+for (let i in list) {
+ console.log(i); // "0", "1", "2",
+}
+
+
+
+
```
## Further Reading