代码如下:
let menus = [
{name:'zh1'},
{name:'zh2'},
{name:'zh3'},
{name:'zh4'},
{name:'zh5'},
{name:'zh6'},
{name:'zh7'},
{name:'zh8'},
{name:'zh9'},
]
let node1_first_index = 0
let node2_first_index = 5
let node2_end_index = 6
let array = []
for (var i = node2_first_index; i < node2_end_index+1; i++) {
array.push(menus[i])
}
// 截取node1,添加到array
for (var j = node1_first_index; j < node2_first_index; j++) {
array.push(menus[j])
}
// 用array覆盖menus从node1_fist_index开始的各项
for (var i = 0; i <array.length; i++) {
menus[node1_first_index+i].name = array[i].name
}
console.log(menus);
期望的输入结果:
[
{name:'zh6'},
{name:'zh7'},
{name:'zh1'},
{name:'zh2'},
{name:'zh3'},
{name:'zh4'},
{name:'zh5'},
{name:'zh8'},
{name:'zh9'},
]
而实际的输出结果:
[
{name:'zh6'},
{name:'zh7'},
{name:'zh6'},
{name:'zh7'},
{name:'zh6'},
{name:'zh7'},
{name:'zh6'},
{name:'zh8'},
{name:'zh9'},
]
请问问题出在什么地方?该如何改正呢?跪求大神解答
k***@163.com (作者)
相当于没回答。该打印的都打印了,就是不知道错在哪里,不然就不会来求助了。不知道大神认真看了没有?看出问题来了没有?
2021-06-20 13:30
k***@163.com (作者)
能回复一下马?
2021-06-20 16:48