function findLongestWord(str) {
var split = str.split(" ");
var longest = 0;
for (var i = 0; i < split.length; i++) {
if (longest < split[i].length) {
longest = split[i].length;
}
}
return longest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
A simple function to find size of the longest word in a string
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.