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

it2022-05-06  0

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);这段代码就是查找数组中重复值所在的那个对象

转载于:https://www.cnblogs.com/guangzhou11/p/9967534.html


最新回复(0)