longest string javascript code example
Example 1: Convert longest string in array
const findLongest = words => Math.max(...(words.map(el => el.length)));
// Example
findLongest(['always','look','on','the','bright','side','of','life']); // 6
Example 2: js find longest word in string function
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}