I need to create a mapping of the $scope.filters
object to a new variable called criteria
, based on whether the original fields are null or not.
For example:
$scope.filters = {
name: 'myName',
lastName: null,
age: null,
}
The desired output for criteria
should only contain non-null values, like this:
var criteria = {
name: 'myName';
}
I attempted the following logic:
var criteria = {};
angular.forEach($scope.filters, function (value, key, obj) {
if (value != null) {
this.push(obj)
}
}, criteria);
However, it seems that I am missing some key aspect in my approach.