InterviewSolution
Saved Bookmarks
| 1. |
How do you iterate a jquery collection? |
|
Answer» The main problem here is that calling APPEND() in a loop is costly and slow. To optimize it, append them all at once rather than one at a time in the loop as shown below. let listHtml = ""; $.each(myArray, function(i, item) { listHtml += "<li>" + item + "</li>"; }); $("#list").html(listHtml);In the above CODE, the list of all list items html is prepared within each loop and then UPDATES the html at the END. |
|