라이브러리
[JAVASCRIPT] str.toLowerCase() - 문자열을 소문자로 변환
toLowerCase() 메서드란?
`toLowerCase()` 메서드는 문자열을 모두 소문자로 변환하는 메서드입니다. 이 메서드는 문자열의 모든 글자를 소문자로 바꿔줍니다.
사용법
`toLowerCase()` 메서드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
javascript
const str = "Hello World!";
const lowerCaseStr = str.toLowerCase();
console.log(lowerCaseStr); // "hello world!"
위의 예제에서 `"Hello World!"` 문자열을 모두 소문자로 변환하여 `lowerCaseStr` 변수에 저장한 후 `console.log()` 함수를 사용하여 출력했습니다.
예제:
#hostingforum.kr
javascript
// 문자열을 모두 소문자로 변환
const str1 = "Hello World!";
const lowerCaseStr1 = str1.toLowerCase();
console.log(lowerCaseStr1); // "hello world!"
// 문자열을 모두 대문자로 변환
const str2 = "hello world!";
const upperCaseStr2 = str2.toUpperCase();
console.log(upperCaseStr2); // "HELLO WORLD!"
// 문자열을 모두 소문자로 변환하고, 공백을 제거
const str3 = " Hello World! ";
const lowerCaseStr3 = str3.toLowerCase().trim();
console.log(lowerCaseStr3); // "hello world!"
위의 예제에서 `toLowerCase()` 메서드를 사용하여 문자열을 모두 소문자로 변환하고, `toUpperCase()` 메서드를 사용하여 문자열을 모두 대문자로 변환했습니다. 또한 `trim()` 메서드를 사용하여 문자열의 공백을 제거했습니다.
주의점
`toLowerCase()` 메서드는 문자열의 모든 글자를 소문자로 변환합니다. 따라서 이 메서드를 사용할 때는 주의해야 합니다. 예를 들어, `"Hello"` 문자열을 모두 소문자로 변환하면 `"hello"`가 됩니다. 하지만 `"hello"` 문자열을 모두 소문자로 변환하면 `"hello"`가 됩니다. 따라서 `"hello"` 문자열을 모두 소문자로 변환하는 것은 의미가 없습니다.
결론
`toLowerCase()` 메서드는 문자열을 모두 소문자로 변환하는 메서드입니다. 이 메서드를 사용할 때는 주의해야 하며, 문자열의 모든 글자를 소문자로 변환해야 할 때 사용합니다.
댓글목록
등록된 댓글이 없습니다.