var arr = [1,2,2,1,1,1,1,1,0,0,0,0,2,1,1,2,0,0,2,1], temp = 0, max = 0, num = 0; for (var i=0; i<arr.length; i++) { if(arr[i] == num) temp++; else temp = 0; if(temp > max) max = temp; } alert(max)