replaced for loop with .forEach for ie8 compatibility

when Array has `undefined` modern browsers ignore it in for loop but ie8 doesn't.
so replaced it with .forEach