js获取数组,进行循环处理,添加,删除,查找等操作

//js循环 添加
that.workTypeActiveIds.forEach(function (value, key, iterable) { console.log(key, value, iterable); var work = that.workTypesItemAll.find(function (work) { return work.id === value }); that.WorkTypeActiveTtems.push(work); that.workTypes.push(work.text); });

js查找索引和删除

 // 查询元素在数组中的索引值
        Array.prototype.indexValue = function (arr) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == arr) {
                    return i;
                }
            }
        }
        Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };

根据值进行查找

  var salary = that.salaryList.find(function (salary) {
                                return salary.id === result.JobInfo.SalaryTypeId;
                            });

 

posted @ 2020-09-21 16:58  net开发人员  阅读(941)  评论(0编辑  收藏  举报