Encontrando a palavra mais longa em uma corda

// https://dev.to/estheragbaje/three-ways-to-find-the-longest-word-in-a-string-using-javascript-5236

// For Loop
function findLongestWord(str) {
  const splStrArray = str.split(' ');

  //initialize a variable to store the longest word
  let longestWord = "";
  for(let index = 0; index < splStrArray.length; index++){
    if(splStrArray[index].length > longestWord.length){
         longestWord = splStrArray[index];
     }
  }
 return longestWord // put.length for integer result
}
Ralph Dizon