I am currently dealing with an object that looks like this:
Object {val1: "Hello", val2: "", dt1: "pilo1", dt2: "pilo2", lo1: "log1"}
My goal is to remove any keys within the object that have empty values ("").
I attempted the following code snippet:
angular.forEach($scope.test,function(value,key){
if(value==""){
var index = $scope.test.indexOf(key);
$scope.test.splice(index,1);
}
});
//$scope.test={val1: "Hello",val2: "",dt1:".......}
However, there is one more important consideration - the keys in the object are not fixed. They may change based on certain conditions. For example:
{val1: "",val2:"Hello1",val3:"",val4:"Hello3",dt1:""}
Therefore, I am seeking a generic solution.