for-in 循环的下标为字符串,不是数字
var ar=[13,2,13,14]; function isSort(ar){ for(var i in ar){ console.log(i+':'+ar[i],i+1+':'+ar[i+1]); if(ar[i]>ar[i+1]){ return -1; } } return 1; } console.log(isSort(ar));
结果: