使用console.log的荒谬输出

时间:2019-06-29 19:40:32

标签: javascript arrays

第一个console.log输出一半的分数,而不是原始数组

const scores = [{a: 78}, {a: 56}, {a:34}];

console.log(scores);


let ship = function(b){

    b.map(score => {        
        score.a /= 2;
        return score;
    });

}

ship(scores);
console.log(scores);

实际输出:
 [{a:39},{a:28},{a:17}]
              [{a:39},{a:28},{a:17}]

预期输出:
[{a:78},{a:56},{a:34}]
               [{a:39},{a:28},{a:17}]

一行一行地粘贴到控制台会给我预期的输出,但作为一个js文件,它会给我真实的输出,如上所示

0 个答案:

没有答案