var alphabet =['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; for(var i = 0; i<= alphabet.length; i++) { alphabet[i] = alphabet[i].toLowerCase(); } 

Mistake:

Uncaught TypeError: Cannot read property toLowerCase of undefined.

Why is alphabet [i] - undefined ?

Closed due to the fact that off-topic participants Grundy , Visman , VenZell , Kromster , pavel 9 Aug '16 at 13:03 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Grundy, Visman, VenZell, Kromster, pavel
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • because a typo should be < instead of <= - Grundy
  • account starts from zero instead of i <= alphabet.length try i <alphabet.length - HELO WORD
  • Thanks guys! - Sergey Alekseev
  • @Grundy, thanks! - Sergey Alekseev

1 answer 1

You have an error in the loop, i <= alphabet.length here i will be 1 more than the array itself, which leads to the fact that the array element is not defined, considering that the array indexing starts from 0.

 for(var i = 0; i < alphabet.length; i++) { alphabet[i] = alphabet[i].toLowerCase(); } 

If you write like that then everything gets better.

  • The array is not defined, in the array element at the specified index - Grundy
  • @Grundy Yes, I corrected :)) - E1mir