Add two conditions in filter Javascript

前端 未结 1 740
说谎
说谎 2021-01-29 09:55

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 t

相关标签:
1条回答
  • 2021-01-29 10:20

    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)
    });
    
    0 讨论(0)
提交回复
热议问题