forEach loop through two arrays at the same time in javascript

Use the second parameter forEach accepts instead, which will be the current index you’re iterating over: n = [1,2,3,5,7,8,9,11,12,13,14,16,17,18,20,21,22]; n.forEach((element, index) => { console.log(element, index); }); If you have two separate arrays to begin with, in each iteration, access the [index] property of the other array: var n = [1, 2, 3, 5, 7, 8, … Read more

success callback after knockout.js finishes rendering all the elements

You have the afterRender callback in knockout.js: foreach: { data: myItems, afterRender: renderedHandler } Here’s documentation. Inside your handler check whether the length of the rendered collection is equal to the length of the items collection. If not don’t execute the full rendered logic that you intend to use. renderedHandler: function (elements, data) { if … Read more