One of the easiest and cleanest solutions is to filter out falsy values with Boolean
constructor, which converts argument to true/false
value. You can also use double negation to convert it.
const myArray = ["a", "", [], null, undefined, NaN, 1, {}, 0, true, false]; const onlyTruthy1 = myArray.filter(Boolean); const onlyTruthy2 = myArray.filter((v) => !!v); console.info(onlyTruthy1); // ["a", [], 1, {}, true] console.info(onlyTruthy2); // ["a", [], 1, {}, true]