Skip to content Skip to sidebar Skip to footer

Add Two Conditions In Filter Javascript

Im trying to add two conditions in filter but only one works. The first condition check if it has empty spaces between words and the second condition if words.length is bigger than

Solution 1:

Seems like you want to filter if sumOfWord is not empty and its length is greater than minLength. @Barmar suggests you the good solution, use the following code.

let wordsLength = sumOfSentence.split(" ");    
let longWords = wordsLength.filter(function(sumOfWord){
    return ((sumOfWord.trim() != '') && sumOfWord.length >= minLength)
});

Post a Comment for "Add Two Conditions In Filter Javascript"