Replace forEach with a loop for IE8