Answers for "javascript find the longest word in a string"

4

javascript find the longest word in a string

function findLongestWordLength(str) {
    let words = str.split(' ');
    let maxLength = 0;
  
    for (let i = 0; i < words.length; i++) {
      if (words[i].length > maxLength) {
        maxLength = words[i].length;
      }
    }
    return maxLength;
  }
  
  
findLongestWordLength("The quick brown fox jumped over the lazy dog");

// 6
Posted by: Guest on June-09-2020
3

js find longest word in string function

function findLongestWordLength(str) {
  return Math.max(...str.split(' ').map(word => word.length));
}
Posted by: Guest on July-24-2020
2

find longest word in string javascript

function data(str){
           var show = str.split(" ");
            show.sort(function (a,b){
                return b.length - a.length; 
            })
            return show[0];
      }
      console.log(data(str = "javascript is my favourite language "));
Posted by: Guest on October-18-2020

Code answers related to "javascript find the longest word in a string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language