Skip to content
Browse files

fixed typo (or to of) formatting and added arguments object example

  • Loading branch information...
1 parent c11eb8f commit f806982ac50828d70e3a5cf4afdba0d4e44b2618 @MatForsberg MatForsberg committed
Showing with 38 additions and 6 deletions.
  1. +38 −6 js-for-of-loop.md
View
44 js-for-of-loop.md
@@ -1,4 +1,4 @@
-The `for..or` statement creates a loop Iterating over iterable objects (including Array, Map, Set, arguments object and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property.
+The `for..of` statement creates a loop iterating over iterable objects (including Array, Map, Set, Arguments object and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property.
```js
for (variable of object) {
@@ -11,10 +11,10 @@ for (variable of object) {
| variable | On each iteration a value of a different property is assigned to variable. |
| object | Object whose enumerable properties are iterated. |
-[MDN link](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) | [MSDN link](https://msdn.microsoft.com/library/dn858238%28v=vs.94%29.aspx?f=255&MSPPError=-2147217396)
-
-## Examples
+[MDN link](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) | [MSDN link](https://msdn.microsoft.com/library/dn858238%28v=vs.94%29.aspx?f=255&MSPPError=-2147217396) | [arguments\[@@iterator\]()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/@@iterator)
+## Examples
+### Array
```js
let arr = [ "fred", "tom", "bob" ];
@@ -27,7 +27,7 @@ for (let i of arr) {
// tom
// bob
```
-
+### Map
```js
var m = new Map();
m.set(1, "black");
@@ -40,4 +40,36 @@ console.log(n);
// Output:
// 1,black
// 2,red
-```
+```
+### Set
+```js
+var s = new Set();
+s.add(1);
+s.add("red");
+
+for (var n of s) {
+console.log(n);
+}
+
+// Output:
+// 1
+// red
+```
+### Arguments object
+```js
+// your browser must support for..of loop
+// and let-scoped variables in for loops
+
+function DisplayArgumentsObject()
+{
+ for (let n of arguments) {
+ console.log(n);
+ }
+}
+
+DisplayArgumentsObject(1,"red");
+
+// Output:
+// 1
+// red
+```

0 comments on commit f806982

Please sign in to comment.
Something went wrong with that request. Please try again.