//数组类
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实现数组类