You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just tried to see how it would look, and I think the current description is within the acceptable range of correctness. The array method docs always start by describing what the user expects to happen—it paints a mental picture, not intended as an exact description of the algorithm. Normally when people think of removing at the beginning, they think of remove and then shift. If we describe it the first time in the most precise way, it's only going to confuse readers because "delete the last element" seems like an unintuitive way to do it. If you want to know the exact algorithm, it's mentioned in the Calling shift() on non-array objects section, because that's where you can actually observe a lot of the peculiarities of the method.
The shift() method reads the length property of this. If the normalized length is 0, length is set to 0 again (whereas it may be negative or undefined before). Otherwise, the property at 0 is returned, and the rest of the properties are shifted left by one. The length property is decremented by one.
However, I found that this paragraph does not mention deleting the last index, which we should.
MDN URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
In Description
The shift() method removes the element at the zeroth index and shifts the values at consecutive indexes down, ....
What did you expect to see?
It should be shifts the values at consecutive indexes down first and remove the last element...
Do you have any supporting links, references, or citations?
Demo:
var array1 = [1, 2, 3]; Object.seal(array1); try {array1.shift()} catch(e){}; console.log(array1); // Output: Array [2, 3, 3]
Do you have anything more you want to share?
No response
MDN metadata
Page report details
en-us/web/javascript/reference/global_objects/array/shift
The text was updated successfully, but these errors were encountered: