From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/string/trim/index.html | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/string/trim/index.html (limited to 'files/ko/web/javascript/reference/global_objects/string/trim') diff --git a/files/ko/web/javascript/reference/global_objects/string/trim/index.html b/files/ko/web/javascript/reference/global_objects/string/trim/index.html new file mode 100644 index 0000000000..0f0b71f548 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/string/trim/index.html @@ -0,0 +1,97 @@ +--- +title: String.prototype.trim() +slug: Web/JavaScript/Reference/Global_Objects/String/Trim +tags: + - ECMAScript 5 + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim +--- +
{{JSRef}}
+ +

trim() 메서드는 문자열 양 끝의 공백을 제거합니다. 공백이란 모든 공백문자(space, tab, NBSP 등)와 모든 개행문자(LF, CR 등)를 의미합니다.

+ +
{{EmbedInteractiveExample("pages/js/string-trim.html")}}
+ + + +

구문

+ +
str.trim()
+ +

반환 값

+ +

양 끝에서 공백을 제거한 새로운 문자열.

+ +

설명

+ +

trim() 메서드는 양끝의 공백을 제거한 문자열을 반환합니다. trim()은 원본 문자열에는 영향을 주지 않습니다. 

+ +

예제

+ +

trim() 사용

+ +

아래의 예제는 소문자 문자열  'foo'를 표시합니다.

+ +
var orig = '   foo  ';
+console.log(orig.trim()); // 'foo'
+
+// 한 쪽의 공백만 제거하는 .trim() 예제
+
+var orig = 'foo    ';
+console.log(orig.trim()); // 'foo'
+
+ +

폴리필

+ +

다른 코드 전에 아래 코드를 실행하면 지원하지 않는 환경에서도  String.trim() 을 사용할 수 있습니다.

+ +
if (!String.prototype.trim) {
+  String.prototype.trim = function () {
+    return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
+  };
+}
+
+ +

명세

+ + + + + + + + + + + + + + + + + + + + + + + + +
표준상태비고
{{SpecName('ES5.1', '#sec-15.5.4.20', 'String.prototype.trim')}}{{Spec2('ES5.1')}}Initial definition. Implemented in JavaScript 1.8.1.
{{SpecName('ES6', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.trim', 'String.prototype.trim')}}{{Spec2('ESDraft')}} 
+ +

브라우저 호환성

+ + + +

{{Compat("javascript.builtins.String.trim")}}

+ +

참조

+ + -- cgit v1.2.3-54-g00ecf