Home > Web Front-end > JS Tutorial > JavaScript method to remove array elements and reduce length_javascript tips

JavaScript method to remove array elements and reduce length_javascript tips

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:23:19
Original
1481 people have browsed it
Copy code The code is as follows:

//Array removal length method

var array =[];
array[0]="Zhang San";
array[1]="Li Si";
array[2]="Wang Wu";
array[3] ="Zhao Liu";
array[4]="Baidu";

function remove(array,index){
if(index<=(array.length-1)){
for(var i=index;iarray[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);
}
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template