Why does console.log wrongly print an empty array?

前端 未结 1 1999
清歌不尽
清歌不尽 2021-01-07 03:15

I use Firefox.

This code logs [].

var log = console.log;

function new_comb(aComb) {
    var res = [];
    log(aComb); // <- This is          


        
1条回答
  •  借酒劲吻你
    2021-01-07 03:45

    console.log shows live data, not a snapshot of the object at the time you run it.

    Since you splice all the data out of the array, it is empty almost as soon as you log it.

    Stringify or deep copy the array if you want to log a snapshot of it.

    0 讨论(0)
提交回复
热议问题