javascript: how to find a longest world in a string a return the length of that word? code example
Example 1: 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 "));
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");