翻转函数reverse的原理
function reverse(arr){ var newArr = [] for(var i = arr.length -1; i >= 0; i--){ // newArr刚开始为空,取到的是0索引,接收arr.length -1索引 newArr[newArr.length] = arr[i] } return newArr; } var na = reverse(['1','2','3','4','5','6']); console.log(na);
function reverse(arr){ var newArr = [] for(var i = arr.length -1; i >= 0; i--){ // newArr刚开始为空,取到的是0索引,接收arr.length -1索引 newArr[newArr.length] = arr[i] } return newArr; } var na = reverse(['1','2','3','4','5','6']); console.log(na);