JavaScriptCheatSheet icon indicating copy to clipboard operation
JavaScriptCheatSheet copied to clipboard

forEach does not modify the array

Open gezeta-id opened this issue 4 years ago • 1 comments

In the subsection Array Methods:

With the exception of forEach, the above functions do not modify the array they are given.

forEach behaves exactly in the same manner as the rest of those functions. None of them, forEach included, modifies the original array.

(But also none of them can prevent that you change it inside the iterating function)

gezeta-id avatar Jan 27 '21 08:01 gezeta-id

In the subsection Array Methods:

forEach takes in each element and consider it for some action, all those mentioned in the section doesn't alter the original array.

suggested fix: xs.forEach(a) to loop over the elements in an array and perform some action.

shamaayilahmed avatar Jan 28 '21 05:01 shamaayilahmed