Last Updated: February 25, 2016
·
583
· merezha

Don't use append inside loops

Bad practice:

$.each(hereArray, function(i, item) {
    var listItem = "<li>" + item + "</li>";
    $("#coolList").append(listItem); 
});

Good practice:

var listItems = "";
$.each(hereArray, function(i, item) {
    listItems += "<li>" + item + "</li>";
});
$("#coolList").append(listItems);

Performance details