-
Uncaught TypeError: Cannot read property ‘toUpperCase’ of undefinedError Collections 2023. 1. 22. 14:55
원인
typeof가 undefined가 형태가 생기는 문자열 for문 loop을 돌리면서 toUpperCase를 하려고 할 때 생겼음
해결
if 문에 typeof형태가 undefined인것을 제외해 주고 loop시켜주면 된다
if(typeof(my_string[i]) !== 'undefined')
function solution(my_string) { var answer = ''; for(let i=0; i<=my_string.length; i++){ if(typeof(my_string[i]) !== 'undefined'){ if(my_string[i] === my_string[i].toUpperCase()){ answer += my_string[i].toLowerCase() }else{ answer += my_string[i].toUpperCase() } } } return answer }
'Error Collections' 카테고리의 다른 글
The requested URL returned error: 403 (0) 2023.02.18 깃헙에러(error: src refspec master does not match any) (0) 2023.01.09 git: Your branch and 'origin/master' have diverged (0) 2023.01.06 GIT GUI (0) 2023.01.05 Positional Argument Follows Keyword Argument In Python (0) 2022.10.09