查找数组中 对象某个值有重复的,将有重复值的对象找出来

时间:2021-02-14 19:54:08
  var  time = obj.biz_date + ' ' + obj.hours;
                  //查找数组中的重复值
                  function find_first(arr, callback) {
                      var val;
                      arr.forEach((elt, i, arry) =>{
                        if(callback(elt)){
                          val = elt;
                        }
                      });
                      return val;
                  }
                  var val = find_first(vm.displays, (elt) => elt.time == time);
                  if(val) {
                    val [obj.age_group] = obj.times;
                  } else{
                    var objdata = {
                        time:time
                     }
                    objdata[obj.age_group] = obj.times;
                    vm.displays.push(objdata);
                  }
                  var val; arr.forEach((elt, i, arry) =>{ if(callback(elt)){ val = elt; } }); return val; } var val = find_first(vm.displays, (elt) => elt.time == time);
这段代码就是查找数组中重复值所在的那个对象