Skip to content

Instantly share code, notes, and snippets.

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

Looping through elements

  • 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

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


  • Unlike array.filter, array.splice mutates the original array. So these two have different use cases. compares array.filter and a regular for-loop. vs for-loop

array.forEach vs for-loop

for-loop vs while-loop

Checking if object has a particular key

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

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

Checking if an element exists in an array

  • 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