I have the following JS array. What's the best way to remove all rows with undefined keys?
json=[{email: "1234569@hhh.pt", first: "Joao", last: "Bastos", gender: "Male", phone: "3.51939e+11"},
{email: "", first: undefined, last: undefined, gender: undefined, phone: undefined},
(...)];
I've tried the following code but is not working. What am I doing wrong?
cleanEmptyRows(json){
var i=0;
var row_to_remove=[];
json.forEach(function(element) {
for (var key in element) {
if(element[key]==null){
row_to_remove.push(i);
break;
}
}
i++;
});
row_to_remove.forEach(function(element){
var index = json.indexOf(element);
if (index > -1) {
json.splice(index, 1);
}
});