From 6f3d7ff69bf779389db1ec44200ccc7af5454862 Mon Sep 17 00:00:00 2001 From: "Isa(yunjongryu)" Date: Thu, 29 Jul 2021 10:02:59 +0900 Subject: etc: 깃 이력추적을 위한 절차 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reference/global_objects/string/trim/index.md | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/string/trim/index.md (limited to 'files/ko/web/javascript/reference/global_objects/string/trim/index.md') diff --git a/files/ko/web/javascript/reference/global_objects/string/trim/index.md b/files/ko/web/javascript/reference/global_objects/string/trim/index.md new file mode 100644 index 0000000000..32c3607a1f --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/string/trim/index.md @@ -0,0 +1,95 @@ +--- +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