1 function findLongestWordLength(str) {
2 let words = str.split(' ');
3 let maxLength = 0;
4
5 for (let i = 0; i < words.length; i++) {
6 if (words[i].length > maxLength) {
7 maxLength = words[i].length;
8 }
9 }
10 return maxLength;
11 }
12
13
14findLongestWordLength("The quick brown fox jumped over the lazy dog");
15
16// 6
1 function data(str){
2 var show = str.split(" ");
3 show.sort(function (a,b){
4 return b.length - a.length;
5 })
6 return show[0];
7 }
8 console.log(data(str = "javascript is my favourite language "));
1function findLongestWordLength(str) {
2 return Math.max(...str.split(' ').map(word => word.length));
3}
1const wordsArray = ['1', '22', '222', 'longstring', '2222']
2const longestWord = wordsArray.reduce((longestWord, currentWord) =>
3 currentWord.length > longestWord.length ? currentWord: longestWord, '');
4console.debug(longestWord); // longstring
1function findLongestWord(str) {
2 var longestWord = str.split(' ').sort(function(a, b) { return b.length - a.length; });
3 return longestWord[0].length;
4}
5findLongestWord("The quick brown fox jumped over the lazy dog");