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/length/index.html | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/string/length/index.html (limited to 'files/ko/web/javascript/reference/global_objects/string/length') diff --git a/files/ko/web/javascript/reference/global_objects/string/length/index.html b/files/ko/web/javascript/reference/global_objects/string/length/index.html new file mode 100644 index 0000000000..697957aaf9 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/string/length/index.html @@ -0,0 +1,84 @@ +--- +title: String.length +slug: Web/JavaScript/Reference/Global_Objects/String/length +tags: + - JavaScript + - Property + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/length +--- +
{{JSRef}}
+ +

length 속성은 UTF-16 코드 유닛을 기준으로 문자열의 길이를 나타냅니다.

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

설명

+ +

length 속성은 문자열 안의 코드 유닛 수를 반환합니다. JavaScript가 사용하는 문자열 형식인 {{interwiki("wikipedia", "UTF-16")}}은 대부분의 일반적인 문자를 표현하기 위해 하나의 16비트 코드 유닛을 사용합니다. 반면, 덜 쓰이는 문자를 표현하기 위해 2개의 코드 유닛을 사용해야 할 때도 있으므로 문자열 내에 있는 문자들의 실제 총 숫자가 length 속성이 반환하는 숫자와 일치하지 않을 수 있습니다.

+ +

ECMAScript 2016 7판은 최대 길이를 2^53 - 1로 설정했습니다. 이전엔 명시된 최대 길이가 없었습니다.

+ +

빈 문자열은 length가 0입니다.

+ +

정적 속성 String.length는 1을 반환합니다. 

+ +

예제

+ +

일반적인 사용법

+ +
var x = 'Mozilla';
+var empty = '';
+
+console.log('Mozilla는 코드 유닛 ' + x.length + '개의 길이입니다.');
+/* "Mozilla는 코드 유닛 7개의 길이입니다." */
+
+console.log('빈 문자열은 ' + empty.length + '의 길이를 가집니다.');
+/* "빈 문자열은 0의 길이를 가집니다." */
+
+ +

명세

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.5.1', 'String.prototype.length')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ESDraft')}} 
+ +

브라우저 호환성

+ +
{{Compat("javascript.builtins.String.length")}}
+ +

같이 보기

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