I hope you're having a great day.
This is pretty straight-forward. I have an object array which I want to filter out, with the help of another array. Scenario is illustrated below:
var ob_array = [
{'a' : 1, 'col_2' : 'abc'},
{'a' : 2, 'col_2' : 'xyz'},
{'a' : 3, 'col_2' : 'jkl'}
];
var my_array = [1, 2];
Expected Output:
var my_array = [
{'a' : 3, 'col_2' : 'jkl'}
]
Tried Approaches:
#1:
ob_array.filter(function(i){
my_array.forEach(function(q){
i['a'] == q
})
});
#2:
ob_array.filter(function(i){
for(var j in my_array){
i['a'] == j;
}
});
I mostly tend to use filter function because I love it. Thanks for viewing this small query of mine. I appreciate your time and efforts.