We have a large array of objects:
var englishStudents = [
{StudentId: 1, Name: "John"},
{StudentId: 2, Name: "Jack"},
{StudentId: 3, Name: "Jane"}
];
Need to check if another similar object is contained in this array, just by comparing one property alone.
var randomStudent = {StudentId: 1337, Name: "Foo"};
This is what I have, and it seems as though it will work, but I don't think this is the best way to do this.
var studentIds = $.map(englishStudents, function (student, index) { return student.StudentId; });
var randomStudentLearnsEnglish = false;
for (var sId in studentIds) {
if (randomStudent.StudentId == sId) {
randomStudentLearnsEnglish = true;
break;
}
}
What would be the optimized way to do this?