.........Find the Longest Word in a String

I dont want to just look up the answer but im not really sure if im even going in the right direction at the moment, some insight would be appreciated! Thank You!

Your code so far

function findLongestWord(str) {
  
var Array = str.split(" ");
  
var arrayLength = Array.length;
  
  for (var i = 0; i < arrayLength; i++) {
    
    if (Array[0] <= Array[1]) {
      
      Array[0].pop();}
     
    else {
      
      if (Array[1] <= Array [0]) {
       
        Array[1].pop();
     }
   }  
 }
  
  return str.length;
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/find-the-longest-word-in-a-string

Thank you very much for the feedback! I did look into the .splice() operator and changed everything around to include that instead but I am at a roadblock where I am getting a type error msg stating that “property length is undefined”. It is my first time using the splice operator and I am wondering where the error is here.

function findLongestWord(str) {

var arraySplit = str.split(" ");

var arrayLength = arraySplit.length;

for (var i = 0; i < arrayLength; i++) {

if (arraySplit[0].length <= arraySplit[1].length) {
  
  arraySplit.splice(0, 1);

}

else {
  
  arraySplit.splice(1, 1);

}
}

return arraySplit[0].length;
}

findLongestWord(“The quick brown fox jumped over the lazy dog”);

You’re not using your index variable i in the for loop.