Here is the data I am working with:
arrayA = [{"studentID":1,"Type":"A"},{"studentID":2,"Type":"B"},{"studentID":3,"Type":"C"},{"studentID":4,"Type":"A"}]
filteredArrayOrderlyOn = [{"studentID":1},{"Type":"A"}] (depends on user-selected filters)
Desired Output for arrayA:
arrayA = [{"studentID":1,"Type":"A"}]
If the filteredArrayOrderlyOn changes based on user input:
filteredArrayOrderlyOn = [{"Type":"B"},{"studentID":1"}] results in no output []
Or if
fillteredArrayOrderlyOn = [{"Type":"A"}]
then output should be:
arrayA = [{"studentID":1,"Type":"A"},{"studentID":4,"Type":"A"}]
I want to filter ArrayA in a specific order, starting with studentID=1 and then Type=A according to the filteredArrayOrderly selection.
I have tried various methods but have not been successful.
newArray = arrayA.filter(function (item) {
return Object.keys(elem) === Object.keys(item);
});
})
Additionally, I have attempted using lodash:
newArray = _.filter(arrayA, function (elem) {
// return elem.Type=== filteredArrayOrderlyOn.Type || elem.studentID=== filteredArrayOrderlyOn.studentID
// });
Unfortunately, I am encountering too many repetitions. Thank you for your help!