首页 > Web开发 > 详细

js 操作数组封装

时间:2014-03-15 06:10:52      阅读:664      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
function OperateArray(array) {
                this.array = array;
            }
            OperateArray.prototype.hasValue = function(val) {
                for (var i = 0; i < this.array.length; i++) {
                    if (this.array[i] == val) {
                        return i;
                    }
                }
                return -1;
            }
            OperateArray.prototype.removeValue = function(val) {
                var index = this.array.indexOf(val);
                if (index > -1) {
                    this.array.splice(index, 1);
                    return this.array;
                }
            }
            var arr = [1, 2, 3, 4, 5];
            var arrcz = new OperateArray(arr);
            arrcz.hasValue(4);//判断是否有数组 大于0:含有  返回数组的下标
            if (arrcz.hasValue(4) > 0) {
                var resultArr=arrcz.removeValue(4);//删除数组
                console.log(resultArr)
            }
bubuko.com,布布扣

js 操作数组封装,布布扣,bubuko.com

js 操作数组封装

原文:http://www.cnblogs.com/baicaocanhua/p/3601164.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!