Find the longest word in a string_Why does this code not work?

Hello. Could someone explain to me why the following code doesn’t work?

function findLongestWordLength(str) {
  let arr = str.split(' ');
  let lengths = [0];
  for (let i = 0; i <= arr.length-1; i++) {
    let counter = arr[i].length; 
    if (counter > lengths[-1]){
      lengths.push(counter);
    } 
  }
  return lengths[-1];
}

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

Ah, I understand now. Thanks!