I deduce the maximum number by function.
var myArray = [0, 1, 9, 4, 3, 2, 8, 6]; var result = myArray[0]; function maxResult(data) { for (i = 0; i < data.length; i++) { if (data[i] > data[0]) { data[0] = data[i]; console.log(data[0]); } } } maxResult(myArray); As a result, in the console, I get the result 1 and 9. I can not understand what the problem is.
Please do not rush slippers, while still studying javascript.
Thanks for answers. The question is closed.
console.log()throughconsole.log(). 1> 0, 9> 1, then all the numbers are smaller. takeconsole.log()over the loop. - Alex