Find the longest word in a string?

前端 未结 8 2307
旧巷少年郎
旧巷少年郎 2021-01-17 05:34

I am trying to write a basic javascript function to find the longest word in a string and log it\'s length.

So far I have:

function findLongestWord(         


        
8条回答
  •  佛祖请我去吃肉
    2021-01-17 06:03

    Your statement

    words.push(str.split(" "));
    

    should be

    words=str.split(" ")
    

    And @Tushar solved the rest of your "problems" too ... ;-)

提交回复
热议问题