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}