I'm having trouble solving this situation where I need to filter an array based on the key values of another array. It might be quite easy but I can't catch the proper key value pairs.
I have this array of marks:
marks = {
eng : 90,
maths : 50,
phy : 60,
chem : 75,
bio : 85,
}
And another array of tags with the same key names:
tags = {
eng : 'English',
maths : 'Maths',
phy : 'Physics',
chem : 'Chemistry',
bio : 'Biology',
}
Now I need to filter tags array if the marks are >65 in marks array and the expected result is:
filteredTags = {
eng : 'English',
chem : 'Chemistry',
bio : 'Biology',
}
Or even better if it is:
filteredTags = ['English', 'Chemistry', 'Biology']
What I have tried so far:
filteredTags = []
$.each(marks, function(ind, val) {
if (val > 60){
filteredTags = tags.filter(function(i,v) {
return (i == ind)
}
})
filteredTags.const filteredTags = Object.keys(marks).filter(key => marks[key] > 65).map(key => tags[key]);