+ 6
What is the difference between "forEach", "for...in" and "for...of"?
My english is not helping me and the translation is too bad... đ https://codeburst.io/javascript-the-difference-between-foreach-and-for-in-992db038e4c2
5 Answers
+ 14
for in is getting the keys of an object, index if it is array.
https://code.sololearn.com/WyWx8udHdDjn/?ref=app
for of is getting the array elements
https://code.sololearn.com/WX2CwmYR8lIo/?ref=app
forEach is an Array method which accepts an argument which is a function with element and index as parameter.
https://code.sololearn.com/WbfJmVR5cCsA/?ref=app
+ 3
Alex Tusinean
The forEach() method calls a function once for each element in an array, in order.
In other words - forEach element of the array, pass that element to a function.
https://www.w3schools.com/jsref/jsref_foreach.asp
https://code.sololearn.com/Wcik1RThrFeu/#js
+ 2
I understand now what is for...in , and for...of, but I still don't understand forEach. đ
+ 2
JS is getting quite cryptic these days, isn't it?
+ 1
forEach is a method from array.prototype, this method accept a argument, an callback function with tow argunents: item element and index element. This method is almost same at map method
for...in and for...of are the control structure syntax, this syntax allow iterate an array, the diference is in for...in return the index and for...of return the element
https://code.sololearn.com/Wi71QLk9Igi7/?ref=app