I got an array of objects Course.
export interface Course {
id: string;
student: User[];
color: string;
}
export interface User {
id: string;
name: string;
//...
}
I need to delete all element of the Course array, if the the student array inside him contain specific id
I was trying to do something like that but I don't understand what I'm suppose to do inside the filter part.
const deleteCourseWhereImIn = (courses: Course[]) => {
const myid = "1111"
return courses.filter((item):Course =>
//[...]
)
};
example:
the input:
const courses = [
{
id : "JSLKLDK",
student: [
{
id: "1111",
name: "John"
},
{
id: "2222",
name: "Ronald"
},
{
id: "3333",
name: "Tim"
},
],
color: "#f01000",
},
{
id : "5JLDKLD",
student: [
{
id: "2222",
name: "Ronald"
},
{
id: "1111",
name: "John"
},
],
color: "#511131",
},
{
id : "PDLFMLZ",
student: [
{
id: "2222",
name: "Ronald"
},
],
color: "#ffffff",
},
]
my ID is 1111
the output should be:
const courses = [
{
id : "PDLFMLZ",
student: [
{
id: "2222",
name: "Ronald"
},
],
color: "#ffffff",
},
]
because I'm john and I'm not in this course.