arrays - About pop() and push() in Javascript -


I'm actually beginning to get started in JavaScript, and as much as I can read, I can read as much.

But when it comes to pop () and push () , then I get some strange results which I am thinking.

Here is the code:

  var arr = []; Arr.push (2,3); Console.log (arrive); Console.log (arr.pop ()); Console.log (arrive);   

The result is:

[2, an unspecified one ?? 1]

3

[2]

It should not be:

[2, 3 ]

3

[2]

< P> This is due to the asynchronous evaluation of console.log on your browser. When the results of the first console.log are displayed, the item has already gone due to pop .

For precise results, call toString () :

  var arr = []; Arr.push (2,3); Console.log (arr.toString ()); // 2.3 - Expected console.log (arr.pop ()); Console.log (arrive);    

Comments