I’m really confused about this.
My understanding was that
array.splice(startIndex, deleteLength, insertThing) would insert
insertThing into the result of
startIndex and delete
deleteLength‘s worth of entries? … so:
var a = [1,2,3,4,5]; var b = a.splice(1, 0, 'foo'); console.log(b);
Should give me:
console.log([1,2,3,4,5].splice(2, 0, 'foo'));
should give me
But for some reason it’s giving me just an empty array? Take a look: http://jsfiddle.net/trolleymusic/STmbp/3/
The “splice()” function returns not the affected array, but the array of removed elements. If you remove nothing, the result array is empty.