String.prototype.trim()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
String ê°ì trim() ë©ìëë 문ìì´ ì ëì 공백ì ì ê±°íë©´ì ì본 문ìì´ì ìì íì§ ìê³ ìë¡ì´ 문ìì´ì ë°íí©ëë¤.
í쪽 ëì ê³µë°±ë§ ì ê±°í ìë¡ì´ 문ìì´ì ë°ííë ¤ë©´ trimStart() ëë trimEnd()를 ì¬ì©íì¸ì.
ìëí´ ë³´ê¸°
const greeting = " Hello world! ";
console.log(greeting);
// Expected output: " Hello world! ";
console.log(greeting.trim());
// Expected output: "Hello world!";
구문
trim()
매ê°ë³ì
ìì.
ë°í ê°
ììê³¼ ëìì ê³µë°±ì´ ì ê±°ë strì ëíë´ë ìë¡ì´ 문ìì´ì
ëë¤. 공백ì 공백 문ìì ì¤ ì¢
ê²°ìë¡ ì ìë©ëë¤.
strì ììì´ë ëì ì´ë í 공백 문ìê° ìëë¼ë, ìë¡ì´ 문ìì´ì´ ë°íë©ëë¤. 기본ì ì¼ë¡ strì ë³µì¬ë³¸ì
ëë¤.
ìì
>trim() ì¬ì©í기
ìë ìì ë str ì ëì 공백ì ì ê±°í©ëë¤.
const str = " foo ";
console.log(str.trim()); // 'foo'
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-string.prototype.trim > |