File tree Expand file tree Collapse file tree 1 file changed +0
-29
lines changed
Expand file tree Collapse file tree 1 file changed +0
-29
lines changed Original file line number Diff line number Diff line change @@ -104,32 +104,3 @@ for (let i of list) {
104104```
105105
106106` for in ` will return a list of keys whereas the ` for of ` will return a list of values of the numeric properties of the object being iterated.
107-
108- The last important difference to cover is the ` for in ` loop will iterate over new properties added to the object.
109-
110- ``` javascript
111- const fruits = [" apple" ," banana" , " orange" ];
112-
113- fruit .eat = " gnam gnam" ;
114-
115- for (const fruit of fruits){
116- console .log (fruit);
117- }
118- // apple
119- // banana
120- // orange
121-
122- for (const index in fruits){
123- console .log (fruits[index]);
124- }
125-
126- // apple
127- // banana
128- // orange
129- // gnam gnam
130- ```
131-
132- Since ` for in ` will return the index and not the value itself, we need to access with the syntax ` fruits[index] ` .
133-
134- As you can see, the ` for in ` loop returned the value of the property ` eat ` which we've added after initialization of the variable ` fruits ` .
135- On the other hand, the ` for of ` loop only returned the values that were in the array when we initialized it.
You can’t perform that action at this time.
0 commit comments