zoukankan      html  css  js  c++  java
  • 数组去重的两种方式

    1.双for循环

     // that.positions.map(train=>{
                                //     that.new_Positions.push( train.trainId)
                                // })
                                //     that.resultArr = [];//去重后的数组
                                //     var flag;
                                //     for (var i in that.new_Positions){
                                //         flag = true;
                                //         for (var j in that.resultArr) {
                                //             if (that.resultArr[j] == that.new_Positions[i]) {
                                //                 flag = false;
                                //                 break;
                                //             }
                                //         }
                                //         if (flag) {
                                //             that.resultArr.push(that.new_Positions[i]);
                                //         }
                                //     }
                                // console.log("that.resultArr:",that.resultArr)

    2.  ... new set 方法

    1           let equipment=[]
    2           this.channelsList.map(item=>{
    3               equipment.push(item.equipmentId)
    4           })
    5           equipment = [...new Set(equipment)];
    6           console.log("equipment:",equipment)
    7           //结果:equipment: (2) ["157680812042523", "157680823318728"]
  • 相关阅读:
    poj2240
    poj1135
    poj1062
    poj3278
    2218 补丁vs错误
    必做: 1041、1024、1077、2218、1183(较难)
    poj2828
    poj3253
    洛谷P1122 最大子树和
    1074 食物链
  • 原文地址:https://www.cnblogs.com/liweiz/p/12331260.html
Copyright © 2011-2022 走看看