I need help converting this jquery loop to a js loop that behaves similar to the each loop but the object properties should be inserted with pure js as I have to query like 2000 elements in the DOM and I need to increase performance a bit.
$(".single-category li").each(function(){
store_games.push({
skin_id : $(this).attr('data-id'),
category : $(this).parent().attr('data-super-category'),
position : $(".single-category li").index(this),
});
});
TO
var sc = document.querySelectorAll(".single-category li");
var len = sc.length - 1;
for (var i = 0; i <= len; i++) {
store_games.push({
skin_id : $(this).attr('data-id'),
category : $(this).parent().attr('data-super-category'),
position : $(".single-category li").index(this),
});
}
Can you help?
For the first two properties I'd do :
skin_id : sc[i].getAttribute("data-id");
category : sc[i].parentNode.getAttribute("data-super-category")
The third one I need help with and if you see further how can I increase performance please let me know.