Fixed undefined issues about for loops (explanation below)
If for a strange reason the "result" variable is undefined or null in
the map() function the for loops that was using the syntaxt for(var i = 0; i < results.length ; i++){ }
would throw an error because of calling 'length' property on an undefined object.
The "foreach" syntaxt for the for loop avoid this problem.