How to find the longest string in an array of strings in Node.js

1 Answer

0 votes
const strings = ["c++", "node.js", "python", "c#", "swift", "java"];
 
const longestString = strings.reduce((a, b) => a.length >= b.length ? a : b);
 
console.log(longestString);
 
 
 
/*
run:
 
node.js
 
*/

 



answered Oct 2, 2024 by avibootz
...