I have an array, and I want to filter it to only include items which match a certain condition. Can this be done in JavaScript?
Some examples:
[1, 2, 3, 4, 5, 6, 7, 8] // I only want [2, 4, 6, 8], i.e. the even numbers
[This, is, an, array, with, several, strings, making, up, a, sentence.] // I only want words with 2 or fewer letters: [is, an, up, a]
[true, false, 4, 0, abc, , 0] // Only keep truthy values: [true, 4, abc, 0]