I have the following code:
allDesignDocs.rows.forEach((row: any) => {
if (!designDocsName.includes(row.id.replace("_design/", ""))) {
toBeRemoved = [{ _id: row.id, _rev: row.value.rev, "_deleted": true }, ...toBeRemoved];
}
});
which works fine. However I would like to use an in place update approach. So I chose map rather than foreach:
var test = allDesignDocs.rows.map((row: any) => {
if (!designDocsName.includes(row.id.replace("_design/", ""))) {
return { _id: row.id, _rev: row.value.rev, "_deleted": true };
}
});
So the above returns arrays including undefined when the condition is not happy. I just want the array to contains values returned from inside if and ignore all undefined. I know I can loop trhough the result and clean it but that is not a clean way. Is there any es6 function which can provide the above functionality?