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

JS implements JAVA's List function

不言
Release: 2018-03-30 18:02:53
Original
1723 people have browsed it

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;
    }
}
Copy after login

                                                                                                                                            


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template