javascript program to identify the logest word in the sentence code example
Example 1: js find longest word in string function
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
Example 2: 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 "));