According to MDN, I think, array.splice can take 1 argument:
If no howMany parameter is specified (second syntax above, which is a SpiderMonkey extension), all elements after index are removed.
but it's not clear whether the one argument option is a SpiderMonkey extension (there's only one syntax example, which is confusing).
It works in Chrome and Firefox, but I don't know of the compatibility beyond that. Does anybody know definitively?
According to 15.4.4.12 of the ECMAScript specification, the only mentioned prototype is:
Array.prototype.splice (start, deleteCount [ , item1 [ , item2 [ , … ] ] ] )
So no, the second parameter is not optional in my reading.
Per spec, at least two arguments are required.
The ability to call with only one argument is a SpiderMonkey extension to the spec. It's entirely possible that Chrome implemented a similar extension. Looks like so did IE9, Opera, and Safari (just tested in those).
Maybe it's time for a spec change....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With