how to count and return the longest word in a string js code example
Example 1: find length of longest string in array javascript
const findLongest = words => Math.max(...(words.map(el => el.length)));
findLongest(['always','look','on','the','bright','side','of','life']);
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 "));