Changed Array.forEach to for ... in loops