k***@163.com
k***@163.com
  • 发布:2021-06-20 12:56
  • 更新:2021-06-20 13:26
  • 阅读:449

一个奇怪的问题,百思不得其解,请各位帮忙

分类:uni-app
js

代码如下:
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'},
]

请问问题出在什么地方?该如何改正呢?跪求大神解答

2021-06-20 12:56 负责人:无 分享
已邀请:
jasonDev

jasonDev - 努力

这个问题不难,打印出来就知道了啊

  • k***@163.com (作者)

    相当于没回答。该打印的都打印了,就是不知道错在哪里,不然就不会来求助了。不知道大神认真看了没有?看出问题来了没有?

    2021-06-20 13:30

  • k***@163.com (作者)

    能回复一下马?

    2021-06-20 16:48

该问题目前已经被锁定, 无法添加新回复