The main thing you want to do is uniquely identify each entry.
A very quick way would be to concatenate the values into a delimited string, eg
let key = [entry.classKey, entry.teacherKey].join(':')
You could then use this to keep track of existing entries and filter the array. For example, using a Set
...
const person = [
{"classKey": 1, "teacherKey": 1},
{"classKey": 2, "teacherKey": 1},
{"classKey": 2, "teacherKey": 1}
]
const filtered = person.filter(function(entry) {
let key = [entry.classKey, entry.teacherKey].join(':')
return !this.has(key) && !!this.add(key)
}, new Set())
console.info(filtered)
I'm using a some boolean short-circuiting to keep it brief but if it helps explain what's going on, it works like this
if (set.has(key)) {
return false // filter out the duplicate value
} else {
set.add(key) // record the key
return true // keep this value
}
If you're not keen on using a Set
(possibly due to browser compatibility) you could instead keep track using a plain object
const filtered = person.filter(function(entry) {
let key = [entry.classKey, entry.teacherKey].join(':')
return !this[key] && (this[key] = true)
}, Object.create(null))