js循环取出两个属性组成新的属性名称数组
原来的格式:
dataObj: [ { id: 1, pattern: "白天模式", upTime: "08:00", downTime: "18:00", notificationMethod: 1, modelUrgency: ["1", "2", "3", "4"], }, { id: 2, pattern: "夜间模式", upTime: "18:01", downTime: "07:59", notificationMethod: 2, modelUrgency: ["3", "4"], }, ],
想要把 upTime和downTime 取出来 ,放到newTime数组中
实现方法
//for 循环 .data 是原数组 dataObj
for (let i = 0; i < data.length; i++) {
data[i].time = [];
data[i].newtime.push(data[i].upTime, data[i].downTime);
}
console.log(data)