I have my reference array
const reference = ['prefix', 'suffix', 'student_email']
and my object that looks like this
const obj = {
'prefix':'John',
'suffix':'Doe',
'student_email':'johndoe23@rigly.org',
'course_code':'PJ4004',
'professor':'McMillian'
}
I'd like to remove 'course_code' & 'professor' as its not apart of the reference array. How can I do that?
Expected output:
const obj = {
'prefix':'John',
'suffix':'Doe',
'student_email':'johndoe23@rigly.org',
}
What I have:
reference.map(v => {
delete obj[v]; // this will delete what I don't want it to delete
});
How can I only remove those I don't need/ aren't present in the reference array?