How to loop through each array chunk separately in JS