You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
1I'm not sure, but wouldn't .forEach be preferable over .map if you're not returning the array?Cody Geisler– Cody Geisler2018年04月18日 18:14:48 +00:00Commented Apr 18, 2018 at 18:14
-
depends on the desired result for sure! I suppose in this specific case forEarch could be preferable. Either way, one of the two methods is the correct way to goPabs123– Pabs1232018年04月18日 18:18:09 +00:00Commented Apr 18, 2018 at 18:18
-
Do you know if there is a performance difference between .forEach and an actual for loop?Michael– Michael2018年04月18日 18:23:52 +00:00Commented Apr 18, 2018 at 18:23
-
theoretically forEach is a bit slower due to the overhead of calling a function on every single loop (good explanation here stackoverflow.com/a/43821929/1148244), but practically speaking the difference should be insignificant. forEach provides good readability and prevents you from dealing with extra variables, though you should be good to use either onePabs123– Pabs1232018年04月18日 18:27:49 +00:00Commented Apr 18, 2018 at 18:27
-
no problem! be sure to accept the answer if it solved your problem so future readers can benefit :)Pabs123– Pabs1232018年04月18日 18:30:28 +00:00Commented Apr 18, 2018 at 18:30
lang-js