二维数组去重方法

2020-04-28  本文已影响0人  nomooo
            const arrays = [[1,2],[1,2],[2,3],[1,2],[3,4],[1,2]]
            
            const filterArray = array => {
                const newArray = [];
                array.forEach((currentValue) => {
                    let isPush = true;
                    newArray.forEach((currentValueIn) => {
                        if(currentValueIn) {
                            if(currentValue[0] === currentValueIn[0] && currentValue[1] === currentValueIn[1]){
                                isPush = false;
                            }
                                
                        }else{
                            newArray.push(currentValue)
                        }
                    })
                    if(isPush) {
                        newArray.push(currentValue)
                    }
                })
                return newArray;
            }
            
            console.log(filterArray(arrays));

上一篇下一篇

猜你喜欢

热点阅读