Skip to content

Instantly share code, notes, and snippets.

@aprilmintacpineda

aprilmintacpineda/docs.md

Last active Nov 26, 2018
Embed
What would you like to do?
JS code speed tests

Looping through elements

http://jsben.ch/UgRvN

  • Accesses length property every loop.
  • Accesses length property only once and saves it into a constant.
  • Uses forEach method.

Removing an element of an array

http://jsben.ch/Io731

  • array.splice.
  • array.filter.
  • Manually looping through each of the element to create a new array.

Notes

  • Unlike array.filter, array.splice mutates the original array. So these two have different use cases. http://jsben.ch/DA7U2 compares array.filter and a regular for-loop.

array.map vs for-loop

http://jsben.ch/coXD5

array.forEach vs for-loop

http://jsben.ch/XuoTX

for-loop vs while-loop

http://jsben.ch/GjSyQ

Checking if object has a particular key

  • in operator
  • strict comparison operator
  • Object.hasOwnProperty
  • object.key expression

http://jsben.ch/EwSf2

Credits to who ever made it. I simply added a new code block.

Checking if an element exists in an array

http://jsben.ch/JLngr

  • array.indexOf
  • array.includes
  • for-loop
  • while-loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment