The three methods you mentioned have different goals.
The purpose of the Array.prototype.map method is to create a new array with the results of calling the callback function for each element of the array.
The purpose of the Array.prototype.forEach method is to Array.prototype.forEach over an array by executing the provided callback function once for an array element.
The purpose of the for...in statement is to list the properties of an object.
It seems to me that you should avoid the for...in operator for...in order to traverse any array-like object 1 where the real goal is to iterate over the numerical indices, rather than enumerate the properties of the object (even knowing that these indices are properties).
Reasons to avoid for...in for iterating objects that look like an array:
- Iterating over inherited user-defined properties in addition to array elements, if you use, for example, a library such as MooTools that extend the
Array.prototype object, you will see all these extended properties. - The iteration order is arbitrary, the elements cannot be visited in numerical order.
Take a look at this article:
1 By objects like an array, I mean any object that contains sequential numeric properties, and the length property
source share