---
title: "Discussion on \"Finding The Longest Word In A String Using For Loop\" | Hashnode"
description: "Discussion on \"Finding The Longest Word In A String Using For Loop\". This is one of the most frequently asked questions in  JavaScript interviews.\nBoth in Large and Small companies. And ill be glad to share my knowledge with you.\nlet myFunction = (names) => {\nlet myArray = names.split(', ');\nlet maxLength = 0;\nlet res..."
url: "https://hashnode.com/posts/finding-the-longest-word-in-a-string-using-for-loop/5d156011b3c3454021117252"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Finding The Longest Word In A String Using For Loop](https://ayeolakenny.com/finding-the-longest-word-in-a-string-using-for-loop?utm_source=hashnode&utm_medium=feed)

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...

Jun 28, 2019 · ayeolakenny.com  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#es6](https://hashnode.com/tag/es6)
-   [#functions](https://hashnode.com/tag/functions)

## Written by

[Ayeola K Olatunde](https://hashnode.com/@ayeolakenny)

@ayeolakenny · NIGERIA

  
[View profile](https://hashnode.com/@ayeolakenny)

Web Developer

🔅|Tech writer✍🏾🔅|💙JavaScript 🔅|#Codenewbie🔅|Tech enthusiast 👨🏽‍💻 🔅|Lifelong learner #100daysOfCode

## Responses 1

Markdown supported · ⌘↵ to post

[Emran](https://hashnode.com/@emranweb)

[Jun 28, 2019](https://hashnode.com/posts/finding-the-longest-word-in-a-string-using-for-loop/5d156011b3c3454021117252/comment/5d1595a13501027f5153732e)

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));
```
