how to find the longest string in an array javascript 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: js find longest word in string function
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
}
Example 3: javascript find the longest string in array
Math.max(...(x.map(el => el.length)));