개발공부/JavaScript
공백 제거 함수(trim, replace)
김놀먹
2022. 9. 15. 13:14
trim( )
앞 뒤의 공백을 제거해주는 함수 ( trimStart( ) : 앞 / trimEnd( ) : 뒤)
let a = " a b c d e ";
a.trim();
// 'a b c d e'
replace( )
정규식을 함께 이용하여 공백 제거
let text = ' a b c d e';
let regex = / /gi;
text.replace(regex, '');
// 'abcde'