网页特效数组操作实例
<script>
var arr = new array(1,2,3,4,5,6,7,8,9,10,11,12,13);
function getsum(n)
{
return arr.join("*").replace(new regexp("(([^*]+[*]){"+(n-1)+"}[^*]+)[*]","g"),"$1+");
}
alert(getsum(3));
</script>
var arr = new array(1,2,3,4);
如果传入的参数是2
返回的结果是35(1*2+1*3+1*4+2*3+2*4+3*4=35)
如果传入的参数是3
返回的结果是50(1*2*3+1*2*4+1*3*4+2*3*4=50)
再看一简单实例
var clientsids = new array(663,175816,19388,22770,175765,175764,175224,175233,175234,175238,175241,175248,175263,175246,46053,16309);
function array_additem(item){
for(var i = 0; i < clientsids.length; i++){
if(clientsids[i] == item) return;
}
clientsids.push(item);
}function array_removeitem(item){
var tmparray = new array();
for(var i = 0; i < clientsids.length; i++){
if(clientsids[i] != item) tmparray.push(clientsids[i]);
}
clientsids = tmparray;
}