Fre*_*rik 0 javascript arrays push
有没有办法在数组中给出一个特定的索引值。在 PHP 中,我可以这样做 $arr[index] = val;
现在,我用
Array.prototype.insert = function (index, item) {
this.splice(index, 0, item);
};
Run Code Online (Sandbox Code Playgroud)
和
var mute = [];
mute.insert(index, 'value');
Run Code Online (Sandbox Code Playgroud)
但是,如果数组为空,则索引仍为 0。如何获得正确的索引?