zoukankan      html  css  js  c++  java
  • js 删除

    1. /* 
    2.  *  方法:Array.remove(dx) 
    3.  *  功能:根据元素值删除数组元素. 
    4.  *  参数:元素值 
    5.  *  返回:在原数组上修改数组 
    6.  *  作者:pxp 
    7.  */  
    8. Array.prototype.indexOf = function (val) {  
    9.     for (var i = 0; i < this.length; i++) {  
    10.         if (this[i] == val) {  
    11.             return i;  
    12.         }  
    13.     }  
    14.     return -1;  
    15. };  
    16. Array.prototype.removevalue = function (val) {  
    17.     var index = this.indexOf(val);  
    18.     if (index > -1) {  
    19.         this.splice(index, 1);  
    20.     }  
    21. };  
    22.   
    23.   
    24. /* 
    25.  *  方法:Array.remove(dx) 
    26.  *  功能:根据元素位置值删除数组元素. 
    27.  *  参数:元素值 
    28.  *  返回:在原数组上修改数组 
    29.  *  作者:pxp 
    30.  */  
    31. Array.prototype.remove = function (dx) {  
    32.     if (isNaN(dx) || dx > this.length) {  
    33.         return false;  
    34.     }  
    35.     for (var i = 0, n = 0; i < this.length; i++) {  
    36.         if (this[i] != this[dx]) {  
    37.             this[n++] = this[i];  
    38.         }  
    39.     }  
    40.     this.length -= 1;  
    41. };  
  • 相关阅读:
    Nodejs
    webpack与gulp的区别
    gulpjs
    Commonjs、AMD、CMD
    建造者模式
    工厂模式
    设计模式分类
    python的接口
    Python代码教你批量将PDF转为Word
    什么是“堆”,"栈","堆栈","队列",它们的区别?
  • 原文地址:https://www.cnblogs.com/ZH1132672711/p/3737012.html
Copyright © 2011-2022 走看看