I have an array that contains objects of weekdays that I want to filter by elements that contain null in "opens" or "closes" (Don't want them in my final array to exist).
let array = [
[
{"weekday":1,"opens":"09:00","closes":"11:00"},
{"weekday":1,"opens":null,"closes":null}
],
[
{"weekday":2,"opens":"09:00","closes":"11:00"},
{"weekday":2,"opens":"12:30","closes":"17:00"},
{"weekday":2,"opens":"18:00","closes":"null"}
], ...
]
I would like to return a new created array so that I don't alter the original array.
My current solution looks like that but feels ugly
let newArray = [];
array.forEach( (day, index) => {
day = day.filter( timeblock =>
timeblock.opens != null && timeblock.closes != null
);
newArray.push(day);
});
How can I filter nested arrays more elegant? (jsfiddle if needed: https://jsfiddle.net/2jukvsoy/1/)