<script type="text/javascript">
var arr=["我","是","帅哥"];
var newArr=[];
for (var i = arr.length-1; i >=0; i--) {
newArr[newArr.length]=arr[i]
}
console.log(arr)
console.log(newArr)
</script>
请教一下各位,按我的理解,以下代码为什么不能这样写,为什么运行的结果是错误的?
<script type="text/javascript">
var arr=["我","是","帅哥"];
var newArr=[];
for (var i = arr.length-1; i >=0; i--) {
for(var j=0;j<=arr.length;j++){
newArr[j]=arr[i]
//这里不是应该将arr[3]的下标内容帅哥赋给newArr[0]接受帅哥内容吗?
}
}
console.log(arr)
console.log(newArr)
</script>