I have a list of elements and I want to loop all the elements. In jQuery, I can use .each() function to loop the list elements.
$('.elements').each(function(){
// loop
});
Now how do I get the index in each loop?
I can set a variable outside the loop and increase it in each loop.
let i = 0;
$('.elements').each(function(){
// loop
console.log(i);
i++;
});
But I don’t want to do that. Is there a default way to get the index?