根据数组的相同的值进行过滤

Posted wangliko

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了根据数组的相同的值进行过滤相关的知识,希望对你有一定的参考价值。

const arr = [{x: 12, y: 12},{x: 123, y: 123},{x: 124, y: 124},{x: 12, y: 12}];//原数组,如果有相同的测返回true



        for (let i = 0; i < arr.length; i++) {

          const current = arr[i];  //如: {x: 12, y: 12}

          //判断数组里面是否有何current值相同的项,

          let filterArr = arr.filter(item => item.x === current.x && item.y === current.y);

          if(filterArr.length > 1) { // 排除current本身,所以是1 ,大于1则表示有相同的项

            return true;

          }

        }

  

以上是关于根据数组的相同的值进行过滤的主要内容,如果未能解决你的问题,请参考以下文章