๐Ÿ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • ์ฝœ๋ฐฑํ•จ์ˆ˜ (Callback function)
    • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • ์ž๋ฃŒ๊ตฌ์กฐ new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • ๊ฐ์ฒด
    • Arguments
    • higher order function
    • operators-function-control-flow
    • ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด 3๊ฐ€์ง€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • ๋ฐ์ดํ„ฐ ํƒ€์ž…
    • Object ๊ฐ์ฒด
    • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
    • ์ฐธ์กฐ
    • ํ•จ์ˆ˜
    • ์ƒ์†(Inheritance)
    • this - 'this'๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ '์–ด๋–ป๊ฒŒ' ์‹คํ–‰ํ•˜๋А๋ƒ์— ๋”ฐ๋ฅธ 4๊ฐ€์ง€ this ์ •์˜
    • ์ „์—ญ๊ฐ์ฒด(Global object)
    • ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - ์ž์—ฐ์ˆ˜, ์ •์ˆ˜, 10์ง„์ˆ˜, 2์ง„์ˆ˜, ๋ถ€๋™์†Œ์ˆ˜์ , ์‹ค์ˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ž˜์Šค, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์กด์žฌํ• ๊นŒ?
    • Hooks๊ณผ useEffect ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ
    • Route
    • async wait ์‚ฌ์šฉํ•˜๊ธฐ
    • Hooks API Reference
    • context
    • npm uninstall ํ•˜๋Š”๋ฒ•
    • test ๋งŒ๋“ค๊ธฐ
  • tip
    • ํด๋ฆฐ์ฝ”๋“œ
    • BxSlider๋กœ ํ…์ŠคํŠธ ํ๋ฅด๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 2๋ถ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • ๋จธ์ง€ ํ›„ branch ์‚ญ์ œํ•˜๊ธฐ
    • ์ง€์˜ฅ์—์„œ ์˜จ Git
    • reset-revert
    • develop branch ๋ฅผ pull ํ•˜๊ณ  ์‹ถ์„๋•Œ
  • conference-and-seminar
    • ๋ชจ๋˜ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ ์ดํ•ด
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ
    • ์Šค์Šค๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋ฒ•
    • ๋ฐ”๋‹๋ผ์ฝ”๋”ฉ ์ˆ˜๊ฐ• ํ›„๊ธฐ
    • async ๊ณผ์ œ ํ›„๊ธฐ - ๋น„๋™๊ธฐ, ๋™๊ธฐ, ํด๋กœ์ €, ๋ฐฐ์—ด๊ณผ ๊ฐ์ฒด
    • ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์Œ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • ํƒ€์ž…๊ณผ ์ถ”์ƒํ™”
      • ๊ฐ์ฒด ์ง€๋„
      • ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ๊ฐ์ฒด
      • ์ถ”์ƒํ™” ๊ธฐ๋ฒ•
      • 05. ์ฑ…์ž„๊ณผ ๋ฉ”์‹œ์ง€
      • 07.ํ•จ๊ป˜ ๋ชจ์œผ๊ธฐ
      • 04. ์—ญํ• , ์ฑ…์ž„, ํ˜‘๋ ฅ
      • ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • ์›น ๋ธŒ๋ผ์šฐ์ €์— URL์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ์›น ํŽ˜์ด์ง€๊ฐ€ ๋ณด์—ฌ์งˆ๊นŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex ํ•ด๋ฒ„๋ ธ์ง€ ๋ญ์•ผ
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd ๋ช…๋ น์–ด ๋ชจ์Œ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN ์„ค์ •ํ•˜๊ธฐ
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans ์˜ค๋‹ต๋…ธํŠธ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 2/2
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 1/2
  • you-dont-know-js
    • ํƒ€์ž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • Syntax
  • Description
  • Unicode
  • Examples
  • length ํ• ๋‹นํ•˜๊ธฐ

Was this helpful?

  1. javascript-api

string.length

length ๋Š” UTF-16 ์ฝ”๋“œ ์œ ๋‹›๊ธฐ์ค€์œผ๋กœ ๋ฌธ์ž์—ด ๊ธธ์ด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” String object์˜ property์ด๋‹ค. string instance์˜ ์ฝ๊ธฐ ์ „์šฉ ๋ฐ์ดํ„ฐ ํ”„๋กœํผํ‹ฐ์ด๋‹ค.

const str = '๊ณ ์–‘์ด ์ตœ๊ณ ์–';
str.length; // 7

Syntax

string.length

Description

๋ฌธ์ž์—ด์— ์ฝ”๋“œ ์œ ๋‹› ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. JavaScript๋Š” ๋ฌธ์ž์—ด ํฌ๋งท์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” UFT-16์€ ๊ธฐ๋ณธ ๋ฌธ์ž๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด 16๋น„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ž๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด 2๊ฐœ์˜ 16 ๋น„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‹ค์ œ ๋ฌธ์ž์™€ ์ผ์น˜ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค.

ECMAScript 2016์€ ์ตœ๋Œ€ ๊ธธ์ด๋ฅผ 2^53 - 1๋กœ ์žฌ์ •์˜ํ•˜์˜€๋‹ค. ๊ทธ ์ด์ „์—๋Š” ์ตœ๋Œ€ ๊ธธ์ด๋Š” ์ •ํ•ด์ ธ ์žˆ์ง€ ์•Š์•˜๋‹ค. Firefox์— ์žˆ๋Š” ๋ฌธ์ž์—ด์˜ ์ตœ๋Œ€ ๊ธธ์ด๋Š” 2**30 - 2 (~1GB) ์ด๋‹ค. Firefox 65 ์ด์ „์˜ ์ตœ๋Œ€ ๊ธธ์ด๋Š” 2**28-1(~256MB) ์˜€๋‹ค.

๋นˆ ๋ฌธ์ž์—ด์ธ ๊ฒฝ์šฐ length๋Š” 0dlek.

์ •์  ์†์„ฑ String.length๋Š” ๋ฌธ์ž์—ด์˜ ๊ธธ์ด์™€ ์ƒ๊ด€์ด ์—†์œผ๋ฉฐ String ํ•จ์ˆ˜์˜ arity(ํ•จ์ˆ˜๊ฐ€ ์ทจํ•˜๋Š” ์ธ์ˆ˜(arguments๋˜๋Š” ํ”ผ์—ฐ์‚ฐ์ž(operand)์˜ ์ˆซ์ž) ์ด๋‹ค. 1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๐Ÿค”

Unicode

๋ฌธ์ž๋Œ€์‹  code unit์„ ์„ธ๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ž ์ˆ˜๋ฅผ ์–ป์œผ๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ์ด ํ•„์š”ํ•˜๋‹ค. ๐Ÿ‘‡

function getCharacterLength (str) {
  // ์—ฌ๊ธฐ์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฌธ์ž์—ด ์ˆœํšŒ๋Š” ๋‹จ์ˆœํ•œ ์ฝ”๋“œ ๋‹จ์œ„๊ฐ€ ์•„๋‹ˆ๋ผ ๋ฌธ์ž ์œ„์—์„œ ์ˆœํšŒํ•œ๋‹ค.
  return [...str].length; // ๐Ÿง ๋ฐฐ์—ด์˜ ์š”์†Œ๋กœ ๋งŒ๋“  ํ›„ ๊ทธ length 
}

console.log(getCharacterLength('A\uD87E\uDC04Z')) // 3

// ๊ถŒ์žฅํ•˜์ง„ ์•Š์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

Object.defineProperty(String.prototype, 'charLength', {
  get () {
    return getCharacterLength(this);
  }
});

console.log('A\uD87E\uDC04Z'.charLength); // 3

Examples

length ํ• ๋‹นํ•˜๊ธฐ

let myString = "๊ณ ์–‘์ด๋Š” ๊ท€์—ฝ๋‹ค";

// length๋ฅผ ํ• ๋‹นํ•ด๋„ ๊ด€์ฐฐ๊ฐ€๋Šฅํ•œ ๊ฒฐ๊ณผ๋Š” ์—†๋‹ค. 
myString.length = 4;
console.log(myString);
// expected output: "๊ณ ์–‘์ด๋Š” ๊ท€์—ฝ๋‹ค"
console.log(myString.length);
// expected output: 8
Previousstring.substringNextstring.trim

Last updated 5 years ago

Was this helpful?