This is my first question here, so please be nice :)
I have an array with different names in it. This looks like that: ["student:Monica", "student:Rebecca", "student:James", "teacher:Mr. Anders"]
.
In reality there are more names in there. From this, I want to make a list with only the students and it shouldn't say student:
in front of it.
So I tried to do it like that:
var students_and_teachers = ["student:Monica", "student:Rebecca", "student:James", "teacher:Mr. Anders"];
for (i = 0; i < students_and_teachers.length; i++) {
var a_student_or_teacher = students_and_teachers[i];
if (a_student_or_teacher.startsWith("student:") === true) {
students_and_teachers[i] = a_student_or_teacher.substring(8, 100);
} else {
delete students_and_teachers[i];
}
}
And this works good but now when I show the students and teachers afterwards it looks like that: Array [ "Monica", "Rebecca", "James", , ]
. But it should only have the three students and not the empty things in the end.
Am I doing something wrong?