//将数组根据条件分组 function getTreeDateByParam(list, param, fun){ var data = {}; if(list && list.length > 0){ for(var i = 0; i < list.length; i++){ if(param){ var res = list[i][param] }else if(fun){ var res = fun(list[i]); } if(data[res]){ data[res].push(list[i]); }else{ data[res] = [list[i]]; } } } return data; }
var map = getTreeDateByParam(vacc,'vaccCode');
vacc[0]的vaccCode有值,另外两个是未定义的