How to find the length of the longest string passed as an argument to function in JavaScript

1 Answer

0 votes
function longestString(...args) {
    return Math.max(...args.map(str => str.length));
}

console.log(longestString("aa", "cccc", "d", "fff"));



      
/*
run:
      
4

*/

 



answered May 3, 2024 by avibootz
...