It must also do a bit of work to handle the case where more than one item was passed to push, since you are allowed to make a call like this: abc.push(1,2,3). In the case of, the JS runtime must first call toObject on the argument passed to push. Let’s take a look at the ECMAScript specification to see what it says. The user who asked it was curious whether there would be any performance difference between adding elements to a JavaScript array by calling push, or manually adding a new object to an array by making a call like myArray = obj. This is a short response I wrote to a question on /r/javascript.
0 Comments
Leave a Reply. |