Yep! That's nice one to work with array of primitives. I had this small helper that export from helper file.
export const clearArray = value => { const types = { string: v => !!v, object: v => v && ( Array.isArray(v) ? v : Object.keys(v) ).length, number: v => !Number.isNaN(v), } return types?.[typeof value]?.(value) ?? value; };
and then import it and I put it as argument in the filter method.
import { clearArray } from './helpers'; const collection = [[], {}, "", null, undefined, NaN, "wee"]; const cleanCollection = collection.filter(clearArray); // ["wee"]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yep! That's nice one to work with array of primitives.
I had this small helper that export from helper file.
and then import it and I put it as argument in the filter method.