Ошибка, когда ключевое слово length используется для передачи длин в массив.
I am trying to create an array called lengths which will have all the lengths of the elements in the array new_str. The problem is when I am trying to push each length to the lengths array it says ‘Cannot read property ‘length’ of undefined’. PS : My plan is to use Math.max() inorder to find the maximum length of the string in the array.
Что я уже пробовал:
function findLongestWordLength(str) { var new_str = str.trim().split(" "); var lengths = []; for(var i=0; i <= new_str.length; i++){ lengths.push(new_str[i].length); } console.log(lengths); } findLongestWordLength("The quick brown fox jumped over the lazy dog");