美文网首页
数组遍历修改值

数组遍历修改值

作者: 盖子pp | 来源:发表于2020-12-16 10:30 被阅读0次

    数组对象的格式是直接可以修改值的,按时单纯数组是不能直接改值的

        let arr = [1,2,3,4]
        arr.forEach(item => {
            item = item * 3
        })
        console.log(arr, 'arr')  // [1, 2, 3, 4] "arr"
        arr.forEach((item, index) => {
            arr[index] = arr[index] *3
        })
        console.log(arr, 'brr') //[3, 6, 9, 12] "brr"
    

    相关文章

      网友评论

          本文标题:数组遍历修改值

          本文链接:https://www.haomeiwen.com/subject/rngagktx.html