Posted in Javascript onAugust 30, 2007
<script type="text/javascript">
Array.prototype.insert = function(vVal,nIdx) {
var arrTemp = this;
if(nIdx>arrTemp.length) nIdx=arrTemp.length;
if(nIdx<-arrTemp.length) nIdx=0;
if(nIdx<0) nIdx = arrTemp.length + nIdx;
for(var ii=arrTemp.length; ii>nIdx; ii--) {
arrTemp[ii]= arrTemp[ii-1];
}
arrTemp[nIdx]=vVal;
return arrTemp;
}
var arr=["w","w","w","i","e","c","n","n","e","t"];
alert(arr.join(""));
arr.insert(".",3);
alert(arr.join(""));
arr.insert(".",-3);
alert(arr.join(""));
</script>
给Javascript数组插入一条记录的代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@