復制代碼 代碼如下:
//數組移除長度方法
var array=[];
array[0]="張三";
array[1]="李四";
array[2]="王五";
array[3]="趙六";
array[4]="百度";
function remove(array,index){
if(index<=(array.length-1)){
for(var i=index;i<array.length;i++){
array[i]=array[i+1];
}
}else{
throw new Error('Array index out of bounds!for function is:remove');
}
array.length=array.length-1;
return array;
}
try{
array=remove(array,2);
array=remove(array,2);
alert(array.length);
alert(array);
}catch(e){
alert(e);
}