Created
May 8, 2016 21:57
-
-
Save fogrew/c882a332fb1ed9ae55c18bdbbce17815 to your computer and use it in GitHub Desktop.
JavaScript tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converting NodeList to Arrays | |
[].slice.call(document.querySelectorAll(query)); | |
// Shuffling array’s elements | |
[1,2,3].sort(Math.random() - 0.5); // [2,1,3] | |
// Caching the array.length in the loop | |
for(var i = 0, length = array.length; i < length; i++) { | |
console.log(array[i]); | |
} | |
// Merging arrays | |
var array1 = [1,2,3]; | |
var array2 = [4,5,6]; | |
console.log(array1.push.apply(array1, array2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment