find the longest word in a String

  function findLongestWordLength(str) {
    let words = str.split(' ');
    let maxLength = 0;
  
    for (let i = 0; i < words.length; i++) {
      if (words[i].length > maxLength) {
        maxLength = words[i].length;
      }
    }
    return maxLength;
  }
  
  
findLongestWordLength("The quick brown fox jumped over the lazy dog");

// 6

4.17
6

                                    class Main {
  public static void main(String[] args) {
    // Creating an array called x.
    String[] x = new String[]{&quot;This&quot;, &quot;Should&quot;, &quot;return&quot;, &quot;4&quot;};
    // &quot;x.length&quot; finds the length of the array &quot;x&quot;.
    System.out.println(x.length);
    // returns 4
  }
}

4.17 (6 Votes)
0
3.75
8
Sachin roy 80 points

                                    function findLongestWord(str) {
  // Step 1. Split the string into an array of strings
  var strSplit = str.split(' ');
  // var strSplit = &quot;The quick brown fox jumped over the lazy dog&quot;.split(' ');
  // var strSplit = [&quot;The&quot;, &quot;quick&quot;, &quot;brown&quot;, &quot;fox&quot;, &quot;jumped&quot;, &quot;over&quot;, &quot;the&quot;, &quot;lazy&quot;, &quot;dog&quot;];
	
  // Step 2. Initiate a variable that will hold the length of the longest word
  var longestWord = 0;

  // Step 3. Create the FOR loop
  for(var i = 0; i &lt; strSplit.length; i++){
    if(strSplit[i].length &gt; longestWord){ // If strSplit[i].length is greater than the word it is compared with...
	longestWord = strSplit[i].length; // ...then longestWord takes this new value
     }
  }
  /* Here strSplit.length = 9
     For each iteration: i = ?   i &lt; strSplit.length?   i++  if(strSplit[i].length &gt; longestWord)?   longestWord = strSplit[i].length
     1st iteration:        0             yes             1   if(&quot;The&quot;.length &gt; 0)? =&gt; if(3 &gt; 0)?     longestWord = 3
     2nd iteration:        1             yes             2   if(&quot;quick&quot;.length &gt; 3)? =&gt; if(5 &gt; 3)?   longestWord = 5   
     3rd iteration:        2             yes             3   if(&quot;brown&quot;.length &gt; 5)? =&gt; if(5 &gt; 5)?   longestWord = 5   
     4th iteration:        3             yes             4   if(&quot;fox&quot;.length &gt; 5)? =&gt; if(3 &gt; 5)?     longestWord = 5  
     5th iteration:        4             yes             5   if(&quot;jumped&quot;.length &gt; 5)? =&gt; if(6 &gt; 5)?  longestWord = 6 
     6th iteration:        5             yes             6   if(&quot;over&quot;.length &gt; 6)? =&gt; if(4 &gt; 6)?    longestWord = 6 
     7th iteration:        6             yes             7   if(&quot;the&quot;.length &gt; 6)? =&gt; if(3 &gt; 6)?     longestWord = 6
     8th iteration:        7             yes             8   if(&quot;lazy&quot;.length &gt; 6)? =&gt; if(4 &gt; 6)?    longestWord = 6 
     9th iteration:        8             yes             9   if(&quot;dog&quot;.length &gt; 6)? =&gt; if(3 &gt; 6)?     longestWord = 6 
     10th iteration:       9             no               
     End of the FOR Loop*/

  //Step 4. Return the longest word
  return longestWord; // 6
}

findLongestWord(&quot;The quick brown fox jumped over the lazy dog&quot;);

3.75 (8 Votes)
0
0
6

                                    public static string getBetween(string strSource, string strStart, string strEnd)
{
    int Start, End;
    if (strSource.Contains(strStart) &amp;&amp; strSource.Contains(strEnd))
    {
        Start = strSource.IndexOf(strStart, 0) + strStart.Length;
        End = strSource.IndexOf(strEnd, Start);
        return strSource.Substring(Start, End - Start);
    }
    else
    {
        return &quot;&quot;;
    }
}

0
0
3.67
9

                                    function findLongestWord(str) {
  var longestWord = str.split(' ').sort(function(a, b) { return b.length - a.length; });
  return longestWord[0].length;
}
findLongestWord(&quot;The quick brown fox jumped over the lazy dog&quot;);

3.67 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
find the longest word in array with the substring program to return longest word in the string how to find the longest word in a string using javascript find the longest word in a string in java longest word in string longest word made of other words js How to find the length of an array java find longest word length in a string js find lwngth of array java what's the longest word how to find longest word in a string in js display longest word javascript how do i get longest word in javascript how to store the length of array in java java set length of array longest word in string javascript with algorithm what does array.length return in JAVA find longest word in string js longest word withen the string javascript longest word javascript solution array.length in java import java array index length to find length of array in java Write a program to find the longest word in a given sentence. how to find word in string in c# function that prints the longest word in array js javascript function return longest string fuunction &quot;multiple strings&quot; javascript return longest word compare two strings javascript return longest word compare two string javascript return longest word comapre string javascriptreturn longest word find longest word multippe stringjavascript function longest string in javascript function to get size of array in java JS longest wordd javascript find longest word in string how to find length of aaray in java string find word c# calculate length using array in java how to get length of string array in java how to find the length of array without using length function in java how to find longestwordlength with javascript find word in string in c# java array length n java array leng how to get the length of an array java how to find out array length in java longest substring javascript fin the longest word in a string find the longest word in a string java JS_Strings_Longest_Word javascript find longest word in sentence javascript find longest word with given letters find longest words in string what is the longest word find longest word javascript stack search for word in word c# java check array length equal list string find longest word how to get lenght of array in java a function that takes in a sentence and returns the longest word how can i find the longest word in js All Longest Strings javaScript all longest string javascript write a method that accepts a string named sentence and returns the longest word in that sentence Write a JavaScript function that accepts a string as a parameter and get the longest word within the string. How to find the longest word in a String array javascript how to get length of array in java find word in a string c# search if string is inside a string c# Return the length of the longest word in the provided sentence javascript Write a JavaScript function that accepts a string as a parameter and find the longest word within the string. javascript: find the longest word c# string find word how to find the longest string in an array javascript how to get length of array java javascript longest substring how to initiate the length of an array in java find length of array java how to find size of array in java does java array have size method find the length of the string in array java longest javascript code find longest string js return the length of an array java how to find the length of a string array in java java find string array length function that returns longest string in javascript finding the word in a string c# get matched word in string C# get length of array injava find given string has matched words in C# how to return the longest string in java script how to return the longest of two strings in javascript search string for word c# get and display the length of the array in java find array length java integer length of longest word js get the size of the array in java return longest string javascript how to check size of an array java how to count array length in java how to find string array length in java javascript longest word find longest word length in js how to know a size of an array in java how to identify the length of the array in java how to count the length of array using java not using array.length method how to find the longest word in a string extract that word in javascript how to find the longest word in a string extract that word inj avascript how to find the longest word in a string extract that word injavascript size of an array in java find the longest string in an array javascript find the word in string c# get array length in java longest word javascript gf get size of an array in java how to get size of an array in java javascript search longest word in string c# find contain in string array with length java array length function in java checking length of an array in java write function take aatay of string and return string have length equal to longest length in javascript takes a string of words and returns the longest word in that string javascript c# how to find a word in a string how to find a string word in a sentence in c# find the longest word in a string in js how to find the length of an array in java] How do you search for a word within a string in c sharp how to find the string array length in java how to find a word in string in c# how to search a word in string in c# find the length of a single element in an array java how to check if string contains word in c# how to get the size of an array in java java get array size how to get size of a array in java Implementation to calculate the array size in java length array in java java size of array find array size in java how to get the size of the array in java check if a word is present in a string csharp return longest word in sentence for loop javascript find longest word in sentence for loop javascript longest string substring js .length java array longest word javascript return word how to search a string for a word in c# how to fincd length of array in java how to find length of integer array in java find array length in java length in array in java find array length java arrays.length java sizeof array in java The Longest Substring JS problem how to get array size in java longest substring in javascript how to find size and capacity of an array java method length java array how to get the length of an array in java function that accepts a string and returns the longest word in the string javascript how to find array length in java javascript find longest length java length of array index how to find length of array given by user in java using length method how to find length of array in java using length method The Longest Word JS given two strings return the longest of the string javascript calculating the array size in java how to search by any word in a string c# get array length java how to declare the length of an array in java java get size of array array length methods in java java get length of int array how to find length of integer array in java with elements in array how to find length of integer array in java lenght array java c# find specific word in string how to read the size of an array java search word in string c# how to find the longest word in javascript discover lenght of an array java java find length of strings in an array find longest string javascript string java how to find length of array lengtth of array java array length in hava size of an array java java array.length define length of array java get the length of a string array java .length array java java get length of an array js find longest word length of array in javas java how to find the length of the int array? java how to find the lengthof the int array? longest word in array javascript can you use size of array java array length in java method what do we get array length in java array.size java array java size find the length in array java java array lenght how to check length of array java find length or array java find the length of an array java size of array java java array size how do we get the length of array in java length of integer array in java get length of string array java get length of array in java check word in string c# js longest word java code to read the length of an array miva length of array function longest word javascript c# search word in string finding length of array java get size of array java how to create a function that returns the longest word in a sentence javascript find out length of the array in java length of int array java getting length of array in java how to return the longest word in javascript array java length how to determine the longest word in javascript java length of an array finding longest word in javascript array.length ajva length of array in java length of an array in java java how to find actual length of array c# get if string has word in it search for a word in string c# array.length -1 java js find the longest word in a string find longest substring javascript find length of string array in java find longest string javascript string array length in java How to find a word in a string c# longest javascript code in the world Longest javascripts code array.length in java java array length - 1 c# check if word is in string size of a java array getting size of array in java how to return the length of an array in java program to find longest word in javascript array len java java length of array size of array in java how to find length of int array in java check if word is in string c#$ count the length of the arr using length function in java java .length array string length longest js array length in java java array length method returns the number of elements in array how to find sarray java length java array .length array values.length java find length if array in java java how long is array lengths array length java get length of array java find length of int array java find a word in a string c# length of array in jaba determine longest word javascript sentence java length array find specific word in string c# how to find length of array in java java array length how to print the length of an array in java how to search a word in a string in c# java array leght length of array java java array.length() string contain the word in c# get lenght of string array java how to find the longest word in an array javascript how to find specific word in a string c# get longest word in string javascript java array legth search for word in a string c# determine array length in java accessing an array lenght in java how to find the longest word in a string javascrpit how to find and return the longest word in a string search string for substring c# javascript how to find the longest word in a string and return it javascript how to find the longest word in a string how to see the length of a array in java how to find the sum of an array in java how to get length in array java how to locate a certain substring in c# longest word function js javascript return longest word in a string function .reduce return longest word in string javascript longest word js find the longest word in a string and return the word js find the longest word in a string not index js find the longest word in a string js c# visual studio windows form string contains search text in a string c# find first occurence of longest word js get longest of three words js c# look for all in string how to separate symbols from a string to retrieve longest word javascript how to return longest string in a sentence find longest word in string How to find the shortest word in a string JavaScript How to write a function that will find the longest word in a sentence using javascript check for longest word in string javascript js function returns longest string in a sentence with spaces, numbers symbols javascript return longest word in string reduce to longest word longestword(string) javscrpt how to return the longest word in a string javascript function find or search c sharp get a text from string substring c# find word in c# find word in string + c# find word in string C# Finding longest name in array javascrpt bangla find the Longest Word in a String in JavaScript without split text ind the Longest Word in a String in JavaScript find the longest word in a javascript string c# find a word in a string proble solving finding longer name from array javascript find the longest word in an array javascript with simple javascript how to check the largest text in a string javascript Find The Largest Word And Smallest Word In A Given String javascript finding the longest word in a string javascript findout biggest word of array in js find largerst word from array by using MegaFrind function find larger word in js find longest word in a sentence javascript length of an arry in java javascript remove the longest word in a string find text char in text at the end of text c# find a text from the collection on value in c# c# how to find a string in a string javascript LongestWor Returns the longest word in the array find the longest word in an array javascript return longest word in string should return the longest of the two input strings javascript regex word contains substring c# how to check string array length in java find shortest word in string javascript how to find the longest word in a string javascript find the longest word in a string spearted by comma with indexOf() find the longest word in a string with indexOf() sort string by the longest word c# string find substring find a string in a other string in c# second longest word in array javascript string find c# c# identify string inside a string using regex to find the longest word in a string in javascript c# search for string inside another string finding the length of an array java how to search with contians on part of string c# .net find dif string find and return the longest word in a string find string like c# c# search fraze in string 2- Write a JavaScript code that accepts a string as a parameter and find the longest word within the string find a value in a string c# js return longest word in array c# search for word in string how to find a substring in a string in C# how to find the length of arrayof string in java Create a function longestWord that takes in a sentence and returns the longest word in it javascript Find the Longest Word in a String in javascript longest word javascript regex mdn longest word function in javascript longest word javascript javascript array iteration filter longest word from sentence javascript array iteration filter longest word from sentance c sharp find substring in string how to find a word in a long string javascript find longest word in a string javascript javascript find longest word c# how to find if text is exactly how to find the longest word in a string find all longest words in an array javascript longest word in a string js length of an array java how to get length of arrayl in java how to check length of array in java how to calculate length of array in java longest word in a string array.length java how to find a value in a string c# javascript choose the longest word in a string Find(x=&gt;x where is word c# c# Get string if appriximitly the same find longest even string in array javascript check a sentence in string c# c# search for string in string best way to find the longest word in an array with javascript get longest word in an array of strings using reduce get lowngest word in an array of strings string search c# find words in a text c# search for word in string c# make long word into ... in javascript fint word in text c# js find longest word in string c# substring find word how to print longest number in javascript how to find where a word is in a string c# how to find text in string c# find in string C# search in string c# find longest word in a string how to find longest string javascript put alll txt contents in string c# find longest word in array javascript javascript: how to find a longest world in a string a return the length of that word? how to char if a word is a string c# FIND THE LONGEST WORD PROGRAM IN JAVASCRIPT C# best way to search string for values find word location in C# how to find the longest word from the given string in javascript find longest word in the array C# find in string c# search string for text js print out longest word in a string js find longest vword c# look for string in string how to find longest word in the string find longest word javascript finding a string within a string c# small word contain in a large word in js longest word in a string javascript return longest word javascript filter method filter longest word Write a JavaScript program to input a string and find the longest word within the string. how to search word in string c# finding longest word in a string javascript c# get text from string function to find the longest word in a given string javascript inspect string c# functie find word C# full word javascript longest word in string and return first is two are equal javascript longest word in string c# find words in sentence javascript longest word in string destructuring javascript longest word in string destructioning how to find the longest word in a string js find string in string c# determine if wors are longer javascript string search in c# string find values c# c# search text in string highlight longest word in paragraph js regex C# find string contains string find longest word in array javascript with map function find value in string c# c# string find js how to check which word is bigger find specific string in C# how to search for a string in c# how to find longest word in a string is word in string c# longest of 2 str js function to print biggest string of elements in array javascript longest word in sentence javascript how to find the longest wod in a string find the longest word in string javascript c# fro word in string get all text under a certain word c# c# find value in string get string from txt C# using[] to output a word in a string javascript return largest word in a string Basic Algorithm Scripting: Find the Longest Word in a String how to find longest word in a string in javascript find part of a word c# find the longest word in a string javascript c# string search longest word in string javascript js find longest word in string function get part of word c# how to find a substring in a string c# js longest word in a string Print the longest word in the sentence from input javascript Print the longest word in the sentence. javascript find longest word in javascript get text within C# c# string search and left example longest word in a string javascript longest word in a sentence javascript find text in string c# longest word in javascript c# find all {} in string return the longest word in a string javascript c# find text in string longest word in string js c# find a word in string c# find word in string how to return text in string in c# string searching in C# finding the longestt word in a string and returning the value find longest word in string javascript .net find in string search string inside string C# how to check longest word in a string function find Longest Word() that takes an array of words and returns the length of the longest one JS function findLongestWord() that takes an array of words and returns the length of the longest one find the bigger word in a string javascript c# string contains match char javascript find the longest word in a string c# check string for keywords text to string in c# c# search text starting and ending index find smallest number in array java 8 Find the Longest Word in a String finding the smallest number in an array java change char at a given index in string java what is the size of a char in kotlin finding the length of an array in java how to get the length of a string in javascreipt c# find string in string how to look for substring in string in c# c# find where word is contained in a string How to find the length of an array in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source