728x90
반응형
trim() / trimStart() / trimEnd()
문자열의 앞/뒤 공백을 제거합니다.
trim() : 문자열의 앞/뒤 공백을 제거합니다 trimStart() : 문자열의 앞 공백을 제거합니다 trimEnd() : 문자열의 뒤 공백을 제거합니다
const str1 = " javascript ";
const currentStr1 = str1.trim();
document.querySelector(".sample03_N1").innerHTML = "1";
document.querySelector(".sample03_Q1").innerHTML = str1;
document.querySelector(".sample03_M1").innerHTML = "trim()";
document.querySelector(".sample03_P1").innerHTML = currentStr1;
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;
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;
728x90
반응형
'javascript' 카테고리의 다른 글
JavaScript match() (3) | 2022.08.22 |
---|---|
JavaScript toUpperCase() / toLowerCase() (2) | 2022.08.17 |
JavaScript concat() (2) | 2022.08.17 |
JavaScript replace() / replaceAll() (3) | 2022.08.17 |
JavaScript split() (2) | 2022.08.17 |