Home >Web Front-end >JS Tutorial >JS implements JAVA's List function

JS implements JAVA's List function

不言
不言Original
2018-03-30 18:02:531770browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn