A way I have used filter is to get rid of undefined array elements. It has the risk of filtering all falsey values, but if you know those values are not going to exist or should also be filtered, then array.filter(x => x) is a short bit of code to get rid of the undefined elements in your array.
A way I have used filter is to get rid of undefined array elements. It has the risk of filtering all falsey values, but if you know those values are not going to exist or should also be filtered, then
array.filter(x => x)
is a short bit of code to get rid of the undefined elements in your array.Thanks Matt! Perfectly condensed.