Skip to main content
10 events
when toggle format what by license comment
Dec 26, 2024 at 7:23 comment added Adam Gawne-Cain This way (for-in loop) will perform well with sparse arrays, and it only iterates the array once. So it is performance safe if you want to decrement higher indices and you are not sure if your array is sparse or not.
Sep 9, 2024 at 19:26 history edited rozsazoltan CC BY-SA 4.0
improved code formatting
S Feb 2, 2021 at 23:45 history suggested Masoud Aghaei CC BY-SA 4.0
put your code in code snippet so other users could see the result
Feb 2, 2021 at 20:01 review Suggested edits
S Feb 2, 2021 at 23:45
Sep 24, 2020 at 14:36 history edited Lioness100 CC BY-SA 4.0
formatting
Aug 21, 2016 at 23:20 comment added Beejor I should also reiterate yckart's comment that for( i = 0; i < arr.length; i++ ) would be a better approach since it preserves the exact indices versus whatever order the browser decides to store the items (with for in). Doing so also lets you get the array index of a value if you need it.
Dec 30, 2014 at 16:13 comment added yckart @RolandIllig Except the use of a for in-loop and the fact that the script could stopped earlier, by returning the result from the loop directly. The upvotes are reasonable ;)
May 24, 2014 at 7:02 history edited user456814 CC BY-SA 3.0
Fixed grammar, improved code formatting.
May 24, 2014 at 5:24 history edited Ekramul Hoque CC BY-SA 3.0
added 22 characters in body
Apr 2, 2013 at 10:56 history answered Ekramul Hoque CC BY-SA 3.0