performance enhancement

JavaScript faster for loops


Assuming you want to traverse through an array using for-loop

var array = [...........]

Slow Way

array.forEach(function(x){
    // TODO: Do Something
});

Fast Way

for(var i = 0; i < array.length; i++){
    // TODO: Do Something
}

Faster Way

for(var i = 0, len = array.length; i < len; i++){
    // TODO: Do Something
}

Reference: https://blogs.oracle.com/greimer/entry/best_way_to_code_a

Advertisements