I'm supposed to find the longest string in an array, but can't find what's wrong with my code. Something isn't working when trying to debug in Visual Studio Code it just won't detach. Please help me with what's wrong!
Code:
let arr = ["Orebro", "Sundsvall", "Hudriksvall", "Goteborg"];
function long_string(arr){
let longest="";
for (let i=0;i<arr.length;i++){
if (arr[i]>longest){
longest=arr[i];
}
}
return longest;
}
long_string(arr)
Can anyone spot the mistake?
arr[i]>longestshould bearr[i].length>longest.lengthlengthproperty in yourifcondition instead of comparing string.