Three Ways to Find the Longest Word in a String in JavaScript
Sonya Moisset
54425

function findLongestWord(str) {
 // Get an array with strings
 var arraystr = str.split(‘ ‘);
 // Get an array with strings’s lengths
 var arraylength = arraystr.map(function(item, index, array){return item.length;});
 // find the max value
 return Math.max.apply(null,arraylength);
}

findLongestWord(“The quick brown fox jumped over the lazy dog”);

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.