If you found value in this thread you will most likely enjoy my tweets too so make sure you follow me on Twitter for more information about web development and how to improve as a developer. This article was first published on my Blog
Get a random item from an Array
Use splice() if you want to delete an element from an array
Use map() when looping through arrays
Stop using "=="
Get a random number
The trim() method
The isFinite() method
The toFixed() method
This is a way you can empty an array in JavaScript
Destructuring
I hope found this useful and if you did please let me know. If you have any questions feel free to DM me on Twitter.
Top comments (6)
Please do not use map instead of forEach as a rule.
Map only makes sense if you are mapping.
This is easily misunderstood by beginners i my experience. :)
Totally agree!
Yep 👍
Doing
myArray.length = 0;
is not the way, just go with[]
, easier, more performant and less error-prone.I also think that
.map
instead of.forEach
orfor
is incorrect, you should use the last two to loop arrays and the.map
only if you want a new array instance, by the way.map
is very slow.Wow, man. Amazing article and tips!
I'll be sure to use these a lot!
glad to hear that you liked this mate