hours, times两个数组比对,后生成一个新的数组。希望得到:[{"date":"2017-08-30","hours":[{"hour":"08:00","state":true},{"hour":"08:30"}]},{"date":"2017-08-31","hours":[{"hour":"08:00"},{"hour":"08:30","state":true}]}]//目前代码var hours = [{"hour":"08:00"},{"hour":"08:30"}];var time=[{ "date":"2017-08-30","time":"08:00"},{"date":"2017-08-31","time":"08:30"}]var newdata=[]times.forEach(function(e,i){ hours.forEach(function(a,j){ if(e.date==a.hour){ a.state=true } }) newdata.push({ date:e.date, hours:hours })})console.log(JSON.stringify(newdata))//输出结果[{"date":"2017-08-30","hours":[{"hour":"08:00","state":true},{"hour":"08:30","state":true}]},{"date":"2017-08-31","hours":[{"hour":"08:00","state":true},{"hour":"08:30","state":true}]}]
添加回答
举报
0/150
提交
取消