Javascript Funky array mishap

后端 未结 5 1901
慢半拍i
慢半拍i 2020-12-06 00:09
function a() {
  var b = [\"b\"];
  console.log(b);
  //console.log(b.slice());
  b = b.push(\"bb\"); 
}
a();

In a \"perfect\" world you would thin

5条回答
  •  难免孤独
    2020-12-06 00:46

    I'm assuming this has to do with the way that console.log() works although you're doing something a little funky when you say:

    b = b.push("bb");
    

    you should be able to just say

    b.push("bb");
    

提交回复
热议问题