我有一个对象数组,我需要新对象数组中对象属性值的总和,
输入:
var inputArray = [
{ subject: 'Maths', marks: '40', noOfStudents: '5' },
{ subject: 'Science', marks: '50', noOfStudents: '16' },
{ subject: 'History', marks: '35', noOfStudents: '23' },
{ subject: 'Science', marks: '65', noOfStudents: '2' },
{ subject: 'Maths', marks: '30', noOfStudents: '12' },
{ subject: 'History', marks: '55', noOfStudents: '20' },
.
.
.
];
我需要的输出,
var outputArray = [
{ subject: 'Maths', marks: '70', noOfStudents: '17' },
{ subject: 'Science', marks: '115', noOfStudents: '18' },
{ subject: 'History', marks: '95', noOfStudents: '43' },
.
.
.
];
我想要新对象数组中的总分和科目的学生人数。输入数组中将有 N 个其他学科对象(即地理、物理学等)。