let x = [
{ time: '05:00', value: 'aaa' },
{ time: '06:00', value: 'bbb' },
{ time: '07:00', value: 'ccc' }
];
let y = [
{ time: '06:00', value: 'vvv' }
];
let z = [];
for (let i = 0; i < x.length; i++) {
let obj = { time: x[i].time, value: x[i].value, value2: '' };
for (let j = 0; j < y.length; j++) {
if (x[i].time === y[j].time) {
obj.value2 = y[j].value;
break;
}
}
z.push(obj);
}
console.log(z);
输出结果为:
复制[
{ time: '05:00', value: 'aaa', value2: '' },
{ time: '06:00', value: 'bbb', value2: 'vvv' },
{ time: '07:00', value: 'ccc', value2: '' }
]