I am attempting to create a new array with data that is not duplicated in two existing arrays. I have an object called this.subjects
and properties named this.teacherData
. I have extracted the subjects code from both of these and stored them in separate arrays. Now, my goal is to filter out any data that is not present in both arrays and store it in a third array.
subj: Subjects[];
teacherSubjects: string[];
data: string[];
filteredData: string[];
addsubject: AddTeacherSubject = new AddTeacherSubject();
teacherData: TeacherUpdateDataDto = new TeacherUpdateDataDto();
ngOnInit() {
this._curriculumService.getSubject(this.appSession.tenant.tenancyName)
.finally(() => { this.saving = false;})
.subscribe((result: listResultDtoOfSubjectDto) => {
this.subjects = result.items;
this.teacherSubjects = this.subjects.map(a => a.code);
console.log("All Subjects =" + this.teacherSubjects);
})
this._teacherService.GetTeacherUpdateData(this.appSession.tenant.tenancyName,
this._sharedService.getMessage())
.finally(()=> { this.saving = false;})
.subscribe((result: TeacherUpdateDataDto) => {
this.teacherData = result;
this.subj = this.teacherData.subject;
this.data = this.subj.map(a => a.code);
})
}
this.subjects DTO
(3) [subjectlistDto, subjectlistDto, subjectlistDto]
0 :
subjectlistDto {name: "Mathematics", code: "mathematics", classCode: "bscs",
classNAME: "BSCS"}
1 :
subjectlistDto {name: "English", code: "english", classCode: "bscs",
classNAME: "BSCS"}
2 :
subjectlistDto {name: "Islamiat", code: "islamiat", classCode: "bscs",
classNAME: "BSCS"}
this.teacherData Dto
subject:Array(2)
0:
{code: "mathematics"}
1:
{code: "english"}
I want the filtered data to be stored in the filteredSubjects array. How can I achieve this?