here is my code
JavaScript
x
19
19
1
subjectData = [
2
{name: 'a'},
3
{name: 'b'},
4
{name: 'c'},
5
]
6
7
8
eachStudent.subjectName= [
9
'b', 'c'
10
]
11
12
13
this.eachStudent.subjectName.forEach((v) => {
14
let index = this.subjectData.map((el) => el.name.toLowerCase()).indexOf(v.toLowerCase());
15
if (index > -1) {
16
this.subjectData.splice(index, 1)
17
}
18
})
19
I want to remove indexs from subjectData which is exist in eachStudent.subjectName
and when i console el.name and v I found that one el is similar but always return -1
Plz help
Advertisement
Answer
It’s so much easier to do this with a one liner using filter:
JavaScript
1
2
1
subjectData = subjectData.filter((item => !subjectName.includes(item.name)));
2
Here’s a working stackblitz: