How to find the longest string in an array of strings in JavaScript

1 Answer

0 votes
const strings = ["c++", "python", "c#", "javascript", "swift", "java"];

const longestString = strings.reduce((a, b) => a.length >= b.length ? a : b);

console.log(longestString);



/*
run:

javascript

*/

 



answered Oct 2, 2024 by avibootz
...