How to find out long name in array?

const  names = ['Rohan',  'Roha',  'Shor', 'Salman', 'Rakibul', 'shikdarroy']
function  findLongName(names){


What have you tried?

function longFriendNames(names){
    let largestName = [];
    for( let i = 0; i < names.length; i++){
        const element = names [i];
        if(element > largestName){
            largestName = element;
    return largestName

const names = ['Sohel', 'Rahim', 'Karim', 'Shago', 'Marufkhan']
const bigName = longFriendNames(names);

Is there something wrong with it? Does it give the correct output?

yes ?
what’s problem this code?
and need solution

What value does it give for bigName?

const names = ['Sohel', 'Rahim', 'Karim', 'Shago', 'Marufkhan']
I expected answer showing :Marufkhan but  showing first five character letter name

you are using this.
What are element and largestName?
Can you use > to compare two strings?

how to find largestName

I am not going to give you the answer, but I can help you work to the solution.

That would be the one which is longest, right?
If you want to use the length to find the largestName, why are you comparing the string themselves and not their length here:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.