[JavaScript] 문자열 메소드 - toUpperCase(), indexOf(), trim()

toUpperCase()

- 문자열의 내용을 모두 대문자로 출력

 

 문자열.toUpperCase()
document.write("Hello World".toUpperCase());  // HELLO WORLD

 

 

 

indexOf()

- 문자열에서 특정 문자가 몇 번째 위치에 있는지 찾음

- 문자가 없으면 -1 반환

 

문자열.indexOf(문자)
document.write("Hello World".indexOf('o'));  // 4

 

 

 

trim()

- 문자열의 공백을 없앰

 

문자열.trim()
document.write("     Hello     ".trim());  // Hello