javascript search longest word in string code example
Example 1: js find longest word in string function
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
Example 2: js find longest vword
function findLongestWord(str) {
var longestWord = str.split(' ').sort(function(a, b) { return b.length - a.length; });
return longestWord[0].length;
}
findLongestWord("The quick brown fox jumped over the lazy dog");