I would like to remove objects from array JSON those are not listed in another array.
let originalArray = [{
id: 1,
NoOfEmp: 12,
Wages:1000,
TotalSI: 21,
Salary:3000
}, {
id: 2,
NoOfEmp: 13,
Wages:2000,
TotalSI: 22,
Salary:4000
}]
let keepArrayObjects = ['id','NoOfEmp','Wages']
originalArray = originalArray.filter( function( el ) {
return keepArrayObjects.indexOf( el ) > 0;
} );
console.log(originalArray);
I have tried the above code to remove objects "TotalSI", "Salary" and keep objects that are listed in keepArrayObjects array, but it's not working.
I would like to update the original array itself and Please help me with this.