摘要:
我需要将Students
中的值插入相应的Employees
中,以使Students
值与Employees['avg_rate' and 'expense']
出现在同一数组中;
新的或修改的对象数组应在日期和部门(例如00_Infants)上匹配,然后排除学生和员工中都没有的部门。
谢谢。
// "Students" aka "attendance values by department"
Object
0:
00_Infants: 30
01_Ones: 35
02_Twos: 39
03_Threes: 38
04_Fours: 21
05_School_Age: 0
key: "10-10-2019"
__proto__: Object
1: {key: "10-11-2019", 00_Infants: 33, 01_Ones: 35, 02_Twos: 36, …}
2: {key: "10-14-2019", 00_Infants: 30, 01_Ones: 33, 02_Twos: 40, …}
// "employees"
Array(12)
0:
key: "10-10-2019"
values: Array(11)
0:
key: "00_Infants"
value:
avg_rate: 13.236842105263158
expense: 764.1350000000001
__proto__: Object
__proto__: Object
1: {key: "01_Ones", value: {…}}
2: {key: "02_Twos", value: {…}}
3: {key: "03_Threes", value: {…}}
4: {key: "04_Fours", value: {…}}
5: {key: "06_Floater", value: {…}}
6: {key: "07_Office", value: {…}}
7: {key: "08_Administration", value: {…}}
8: {key: "09_Director", value: {…}}
9: {key: "12_Kitchen", value: {…}}
10: {key: "13_Unknown", value: {…}}
length: 11
__proto__: Array(0)
__proto__: Object
1: {key: "10-11-2019", values: Array(10)}
2: {key: "10-14-2019", values: Array(9)}
所需结果:
{
Date:"10-09-2019"{
00_Infants: {
avg_rate: 13.39,
expense: 776.58,
attendance: 28
},
01_Ones: {
avg_rate: 13.31,
expense: 716.58,
attendance: 33
},
},
{ // for each date
Date:"10-10-2019"{
// for each department ^
}
}
答案 0 :(得分:1)
function newFile() {
var number = '1';
var newFile = SpreadsheetApp.create("Roll " + number);
}
对象的值,而forEach()可用于迭代这些值。students
数组中查找具有匹配日期的员工。employees
可用于查找员工对象中的部门,并可以添加具有适当值的find()
属性。代码:
attendance