Looking at the following array:
const data = [
{id: 1, courses: [{title:"course1.1", results:[]}, {title:"course1.2", results:[]}]},
{id: 2, courses: [{title:"course1.1", results:[]}, {title:"course1.2",results:[]}]},
];
I am attempting to retrieve the first item in the data array that has a course with no results.
I attempted the following approach:
data.filter(session => session.courses.filter(course => course.results.length <= 0));
However, it is returning all items for some unknown reason.
Any assistance on this matter would be greatly appreciated, thank you!
P.S. I have already tried using Array.some and a simple forEach without success.
Edit: I forgot to mention that I conducted a test on jsfiddle, https://jsfiddle.net/jonathanlaf/4os0fzv1/
Edit2: I understand that filter will return all matching results, but I just need to take the first index of the newly returned array.
Edit3: I actually expect the newly returned array to look like this:
const updatedData = [
{id: 2, courses: [{title:"course1.1", results:[]}, {title:"course1.2",results:[]}]},
];