For my project, I have a list of students and am meant to use super basic regular expressions to check their grades. The A and B students are to be added to separate arrays for only those students. The code for doing so is as follows:
const aTest = new RegExp(/(A)/i);
const bTest = new RegExp(/(B)/i);
const aStudents = [];
const bStudents = [];
for (var i = 0; i < students.length; i++) {
if (aTest.test(students[i].grade)) {
aStudents.push(students[i]);
}
if (bTest.test(students[i].grade)) {
bStudents.push(students[i]);
}
}
However, if I were to use forEach instead of a for loop, how should I go about doing so?