This article shares with you the code for JS to implement the List function of JAVA. Friends who are interested can take a look
function List(){ var list = new Array(); /* 添加元素 */ this.add = function(obj){ list[list.length] = obj; } /* 根据下标获得元素 */ this.get = function(index){ return list[index]; } /* 根据下标移除元素 */ this.remove = function(index){ var obj = list[index]; list.splice(index, 1); return obj; } /* 清空对象中元素 */ this.clear = function(){ list.splice(0, list.length); } /* 对象元素大小 */ this.size = function(){ return list.length; } }
The above is the detailed content of JS implements JAVA's List function. For more information, please follow other related articles on the PHP Chinese website!