To get array element fulfilling a condition with JavaScript, we call the filter
method.
For instance, we write
const isGreaterThanFive = (x) => {
return x > 5;
};
const filtered = [1, 10, 4, 6].filter(isGreaterThanFive);
to call [1, 10, 4, 6].filter
with isGreaterThanFive
to return an array with the entries that are greater than 5 in the [1, 10, 4, 6]
array.