728x90
trim() | trimStart() | trimEnd()
trim() : 앞뒤 문자열 공백제거 trimStart() : 앞 공백 제거 trimEnd() : 뒤 공백 제거
//01
const str1 = " javascript ";
const currentStr1 = str1.trim();
document.querySelector(".sample03_N1").innerHTML = "1";
document.querySelector(".sample03_Q1").innerHTML = " javascript ";
document.querySelector(".sample03_M1").innerHTML = "trim()";
document.querySelector(".sample03_P1").innerHTML = currentStr1; // "javascript"
//02
const str2 = " javascript ";
const currentStr2 = str2.trimStart();
document.querySelector(".sample03_N2").innerHTML = "2";
document.querySelector(".sample03_Q2").innerHTML = str2;
document.querySelector(".sample03_M2").innerHTML = "trimStart()";
document.querySelector(".sample03_P2").innerHTML = currentStr2; // "javascript "
//03
const str3 = " javascript ";
const currentStr3 = str3.trimEnd();
document.querySelector(".sample03_N3").innerHTML = "3";
document.querySelector(".sample03_Q3").innerHTML = str3;
document.querySelector(".sample03_M3").innerHTML = "trimEnd()";
document.querySelector(".sample03_P3").innerHTML = currentStr3; //" javascript"
728x90
반응형
'JavaScript' 카테고리의 다른 글
template (2) | 2022.08.17 |
---|---|
toLowerCase() | toLowerCase() (2) | 2022.08.17 |
indexOf() | lastindexOf() (8) | 2022.08.16 |
slice() | substring() | substr() (7) | 2022.08.16 |
정규식 표현 (6) | 2022.08.16 |
댓글