web-profile

JavaScript filter

var customArray = [3, 5, 7];
var moreThan4 = customArray.filter(function(item) {
    if (item > 4) {
        return true;
    }
});
console.log(moreThan4); // 5, 7

Alternative syntax with arrow function:

var customArray = [3, 5, 7];
var moreThan4 = customArray.filter(item => item > 4);
console.log(moreThan4); // 5, 7

Leave a Reply

Your email address will not be published.