我真的很困惑。
我的理解是,这array.splice(startIndex, deleteLength, insertThing)
会插入insertThing
到splice()
atstartIndex
和 deletedeleteLength
的条目价值中吗?... 所以:
var a = [1,2,3,4,5];
var b = a.splice(1, 0, 'foo');
console.log(b);
应该给我:
[1,'foo',2,3,4,5]
和
console.log([1,2,3,4,5].splice(2, 0, 'foo'));
应该给我
[1,2,'foo',3,4,5]
等等
但由于某种原因,它只给了我一个空数组?看看:http: //jsfiddle.net/trolleymusic/STmbp/3/
谢谢 :)