Skip to main content

Find the length of the longest string in an array

JavaScript version

const findLongest = (words) => Math.max(...words.map((el) => el.length));

TypeScript version

const findLongest = (words: string[]): number => Math.max(...words.map((el) => el.length));

Example

findLongest(['always', 'look', 'on', 'the', 'bright', 'side', 'of', 'life']); // 6

Comments