๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : trim() / toUpperCase() / toLowerCase()
trim() ๋ฉ์๋๋ ๋ฌธ์์ด์ ๊ณต๋ฐฑ์ ์ ๊ฑฐํด ์ฃผ๊ณ , toUpperCase() / toLowerCase() ๋ฉ์๋๋ ๋ฌธ์์ด์ ๋ / ์๋ฌธ์๋ก ๋ณํํด ์ค๋๋ค. ํ๋์ฉ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
trim() ๋ฉ์๋
trim() ๋ฉ์๋๋ ๋ฌธ์์ด ์ ๋์ ๊ณต๋ฐฑ์ ์ ๊ฑฐํฉ๋๋ค. ๊ณต๋ฐฑ์ด๋ ๋ชจ๋ ๊ณต๋ฐฑ๋ฌธ์(space, tab, NBSP ๋ฑ)์ ๋ชจ๋ ๊ฐํ๋ฌธ์(LF, CR ๋ฑ)๋ฅผ ์๋ฏธํฉ๋๋ค. trimStart() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ์ ๊ณต๋ฐฑ, trimEnd() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ค ๊ณต๋ฐฑ๋ง์ ์ ๊ฑฐํด์ค ์ ์์ต๋๋ค. ๋ฌธ์์ด ์ค๊ฐ์ ๊ณต๋ฐฑ์ ์ ๊ฑฐํ ์ ์์ต๋๋ค.
const str1 = " javascript "
const currentStr1 = str1.trim(); // ์, ๋ค ๊ณต๋ฐฑ ์ ๊ฑฐ
document.write(currentStr1);
const str2 = " javascript "
const currentStr2 = str2.trimStart(); // ์ ๊ณต๋ฐฑ ์ ๊ฑฐ
document.write(currentStr2);
const str3 = " javascript "
const currentStr3 = str3.trimEnd(); // ๋ค ๊ณต๋ฐฑ ์ ๊ฑฐ
document.write(currentStr3);
๊ฒฐ๊ณผ๋ณด๊ธฐ
javascript________
________javascript
toUpperCase() ๋ฉ์๋
toUpperCase() ๋ฉ์๋๋ ๋ฌธ์์ด์ ๋๋ฌธ์๋ก ๋ณํํด ๋ฐํํฉ๋๋ค.
const str1 = "javascript";
const currentStr1 = str1.toUpperCase();
document.write(currentStr1);
const str2 = "jquery";
const currentStr2 = str2.toUpperCase();
document.write(currentStr2);
๊ฒฐ๊ณผ๋ณด๊ธฐ
JQUERY
toLowerCase() ๋ฉ์๋
toLowerCase() ๋ฉ์๋๋ ๋ฌธ์์ด์ ์๋ฌธ์๋ก ๋ณํํด ๋ฐํํฉ๋๋ค.
const str1 = "JAVASCRIPT";
const currentStr1 = str1.toLowerCase();
document.write(currentStr1);
const str2 = "JQUERY";
const currentStr2 = str2.toLowerCase();
document.write(currentStr2);
๊ฒฐ๊ณผ๋ณด๊ธฐ
jquery
๋๊ธ