This is one of the most frequently asked questions in JavaScript interviews. Both in Large and Small companies. And ill be glad to share my knowledge with you. let myFunction = (names) => { let myArray = names.split(', '); let maxLength = 0; let res...
Markdown supported · ⌘↵ to post
I do that using the for each function
// write a functino to show the longest string from array const names = ["Noman", "John", "Wickago", "Omarfaru", "Faruk", "Shahin"]; function findSting(names) { let max = 0; let name, size; names.forEach(function (item) { if (item.length > max) { max = item.length; name = item; size = max; } }) return ` Longest name: ${name} and Size: ${size}`; } console.log(findSting(names));