Uncaught TypeError: Can not read property 'length' of undefined

0

Good morning, you will suddenly see this error, it marks me error in lenght, and although I try to save the length of my array in a variable, it does not work either, any suggestions?

This is my code, the error is in the second for with newArray [i] .length:

function LongestWord(sen) { 
var word =[];
var newArray=[];
var c_array = 0;
var old_new = 0;
var num_array = 0;
var aux;

for(var i=0; i < sen.length; i++ ){
    if (sen[i].match(/^[a-zA-Z]+$/) || sen[i].match(/^([0-9])*$/)){
            word +=sen[i];

    } else{

    if(word!== " "){
            newArray[c_array] = word;
            c_array++;                  
            word = " ";

          } 

      } 

  }

  newArray[c_array] = word;
  console.log(newArray)

for(var i=0; i<= newArray.length; i++){
    if(newArray[i].length > old_new){
        num_array++;
        old_new = newArray[i].length;  /*Aqui marca error*/


    }else{
        sen = newArray[i -1];
    }

  }
}

/ * Update * /

Modify the code because it did not accept numbers.

    
asked by Lily Hdz 22.05.2018 в 15:27
source

0 answers