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;
                            });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM