Everything is an array index
Javascript engines never cease to amuse me.
Let’s look at our good old Array.prototype.splice
[1,2,3].splice(0,1) //returns [1]
[1,2,3].splice(1,1) //returns [2]
[1,2,3].splice(undefined,1) // 1
[1,2,3].splice(false,1) // 1
[1,2,3].splice(true,1) // 2!
Ok, so splice is accepting non-numbers and it’s casting them to booleans and then to numbers, right? Wrong.
[1,2,3].splice({},1) // 1
[1,2,3].splice("",1) // 1
[1,2,3].splice("one",1) // 1
Confused? That’s still pretty consistent!
Check this out:
[1,2,3].splice([],1) //1
[1,2,3].splice([1],1) //2
[1,2,3].splice([2],1) //3
[1,2,3].splice([1,2],1) //1
Go home javascript, you’re drunk.
Let’s figure this out anyway.
First:
[1,2,3].splice({toString:function(){return 2;}},1) // 3
[1,2,3].splice({toString:function(){return "2one";}},1) // 1
[1,2,3].splice({toString:function(){return "2";}},1) // 3
Ok, that’s something. Looks like...