The code does the following:
- Gets an array of objects and filters them according to some properties
- Returns the array of objects with the filtered data
I'm using the following code which is working and I wonder if there is a way to write it better.
By the way, I can use LodashJS if it's helpful here.
filterNullUndefinedOrRejected: function(oData) {
if (oData && oData.length > 0) {
var aNewExtendedObjects = [];
for (var i = 0; i < oData.length; i++) {
if (oData[i].va === null || oData[i].val === undefined || oData[i].state === "rejected") {
if (oData[i].state === "rejected") {
console.log(oData[i].error);
}
oData.splice(i, 1);
i--;
}
else{
aNewExtendedObjects.push(oData[i].val);
}
}
return aNewExtendedObjects[0];
}
return oData;
},