gpt4 book ai didi

javascript - 为什么 "return"与 "console.log()"不一样

转载 作者:行者123 更新时间:2023-11-30 20:52:31 24 4
gpt4 key购买 nike

<分区>

基本上,我只是尝试将 100 添加到数组 test 中可被 3 整除的元素,然后打印出 test 数组。我不明白的是,当我在函数中使用 console.log(test) 时,它会打印出满足条件的数组,即 100 被添加到可被 3 整除的元素中,但是当我在函数之外使用它时,它不会。这是为什么?有没有办法在函数外满足条件的情况下打印出测试数组?我刚开始学习 javascript,所以我有点初学者。

var test = [12, 929, 11, 3, 199, 1000, 7, 1, 24, 37, 4,
19, 300, 3775, 299, 36, 209, 148, 169, 299,
6, 109, 20, 58, 139, 59, 3, 1, 139
];

test.forEach(function(test){
if(test % 3 === 0){
test+=100;
}
console.log(test);//prints out test array if condition met
});

//console.log(test); //doesn't print test array with if condition met????

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com