在要求输入邮箱的文本域,请填写真实的邮件地址。非真实邮件地址,将收不到回复信息。

Javascript实现数组类

JavaScript 清风 882℃ 0评论
//数组类
function ArrayList() {
    this.length = 0;
    this.array = new Array();
    this.Item = function(index) {
        return this.array[index];
    }
    this.Add = function(value) {
        this.array[this.length] = value;
        this.length++;
    }
    this.Remove = function(value) {
        if (this.length >= 1) {
            for (var i = 0; i < this.length; i++) {
                if (this.array[i] == value) {
                    for (var j = i; j < (this.length - 1); j++) {
                        this.array[j] = this.array[j + 1];
                    }
                    this.length--;
                    this.array[this.length] = null;
                    this.array.length--;
                    break;
                }
            }
        } else {
            this.length = 0;
        }
    }
    this.Insert = function(value, index) {
        if (index < 0){ 
            index = 0;
        } 
       if ((this.length >= 1) && (index < this.length)) {
          for (var i = this.length; i > index; i--) {
                this.array[i] = this.array[i - 1];
          }
          this.array[index] = value;
          this.length++;
        } else {
          this.Add(value);
        }
    }
    this.Exist = function(value) {
        if (this.length > 1) {
            for (var i = 0; i < this.length; i++) {
              if (this.array[i] == value) {
                 return true;
               }
             }
         }
       return false;
     } 
    this.Clear = function() { 
        this.array.length = 0; 
        this.length = 0;
     } 
    this.GetArray = function() {
        return this.array;
    } 
    this.Getlength = function() { 
        return this.length;
     } 
    this.Import = function(splitString, splitChar) {
       this.array = splitString.split(splitChar);
       this.length = this.array.length;
    } 
    this.Export = function(joinChar) {
        var strReturn = ""; 
        if (this.length >= 1) {
           for (var i = 0; i < this.length; i++) {
             strReturn += this.array[i];
             if (i < (this.length - 1)) {
                 strReturn += joinChar;
             }
            }
        }
        return strReturn;
    }
}

 

 

 



转载请注明:清风亦平凡 » Javascript实现数组类

喜欢 (0)or分享 (0)
支付宝扫码打赏 支付宝扫码打赏 微信打赏 微信打赏
头像
发表我的评论
取消评论

CAPTCHA Image
Reload Image
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址