๐Ÿ“
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
  • Parameters
  • Return value
  • Description
  • Examples
  • slice()๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ
  • ์Œ์ˆ˜ ์ธ๋ฑ์Šค๋กœ slice() ์‚ฌ์šฉํ•˜๊ธฐ

Was this helpful?

  1. javascript-api

string.slice

slice() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์˜ ์„น์…˜์„ ์ถ”์ถœํ•˜์—ฌ ์›๋ž˜ ๋ฌธ์ž์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•œ๋‹ค.

const str = 'The cat (Felis catus) is a domestic species of small carnivorous mammal.';
str.slice(31); // "stic species of small carnivorous mammal."
str.slice(4, 19); // "cat (Felis catu"
str.slice(-4); // "mal."
str.slice(-9, -5); // "s ma"

Syntax

str.slice(beginIndex[, endIndex]);

Parameters

beginIndex

์ถ”์ถœ์„ ์‹œ์ž‘ํ•  ์ธ๋ฑ์Šค(0๋ถ€ํ„ฐ ์‹œ์ž‘)์ด๋‹ค. ๋งŒ์•ฝ ์Œ์ˆ˜์ด๋ฉด str.length + beginIndex๋กœ ์ทจ๊ธ‰ํ•œ๋‹ค. (์˜ˆ๋ฅผ ๋‘˜๋ฉด -3์ด๋ฉด str.length + - 3 ์ด๋‹ค)

beginIndex๊ฐ€ str.length์™€ ๊ฐ™๊ฑฐ๋‚˜ ํฌ๋ฉด slice()๋Š” ๋นˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

endIndex (Optional)

์ถ”์ถœ์„ ๋๋‚ด๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” index, ์ด index์˜ ๋ฌธ์ž๋Š” ํฌํ•จ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋งŒ์•ฝ endIndex๊ฐ€ ์ƒ๋žต๋œ๋‹ค๋ฉด, slice()๋Š” ๋ฌธ์ž์—ด ๋งˆ์ง€๋ง‰๊นŒ์ง€ ์ถ”์ถœํ•œ๋‹ค. ๋งŒ์•ฝ ์Œ์ˆ˜๋ผ๋ฉด, endIndex๋Š” str.length + endIndex๋กœ ์ทจ๊ธ‰ํ•œ๋‹ค. (์˜ˆ๋ฅผ ๋“ค๋ฉด endIndex๊ฐ€ -3์ด๋ฉด ์‹œ์ž‘์ ์€ str.length - 3)

Return value

๋ฌธ์ž์—ด์˜ ์„น์…˜์„ ์ถ”์ถœํ•œ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด

Description

slice()๋Š” ํ•œ ๋ฌธ์ž์—ด์—์„œ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜์—ฌ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ํ•œ ๋ฌธ์ž์—ด์˜ ํ…์ŠคํŠธ๋ฅผ ๋ณ€๊ฒฝํ•ด๋„ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค. slice() ๋Š” endIndex ๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค. str.slice(1, 4) ๋Š” ๋‘๋ฒˆ์งธ ๋ฌธ์ž๋ถ€ํ„ฐ ๋„ค๋ฒˆ์งธ ๋ฌธ์ž๊นŒ์ง€ ์ถ”์ถœํ•œ๋‹ค. (1, 2, 3 ์ธ๋ฑ์Šค ๋ฌธ์ž).

str.slice(2, -1) ์„ธ ๋ฒˆ์งธ ๋ฌธ์ž๋ถ€ํ„ฐ ๋ฌธ์ž์—ด์˜ ๋งˆ์ง€๋ง‰์—์„œ ๋‘๋ฒˆ์งธ ๋ฌธ์ž๊นŒ์ง€ ์ถ”์ถœํ•œ๋‹ค.

Examples

slice()๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ

let str1 = 'Cats are common pets throughout the world, and their worldwide population exceeds 500 million as of 2007.',
    str2 = str1.slice(1, 8),
    str3 = str1.slice(4, -2),
    str4 = str1.slice(12),
    str5 = str1.slice(30);
str2; // "ats are"
str3; // " are common pets throughout the world, and their worldwide population exceeds 500 million as of 200"
str4; // "mon pets throughout the world, and their worldwide population exceeds 500 million as of 2007."
str5; // "t the world, and their worldwide population exceeds 500 million as of 2007."

์Œ์ˆ˜ ์ธ๋ฑ์Šค๋กœ slice() ์‚ฌ์šฉํ•˜๊ธฐ

let str = 'Cats are common pets throughout the world';
str.slice(-1); // "d" str.length-1 ๋ถ€ํ„ฐ ๋๊นŒ์ง€์ด๋‹ค.
str.slice(-1, -1); // ""
str.slice(-3); // "rld" str.length - 3 ๋ถ€ํ„ฐ ๋๊นŒ์ง€์ด๋‹ค.
str.slice(-3, -1); // "rl"  str.length - 3 ๋ถ€ํ„ฐ str.length - 1์„ ํฌํ•จํ•˜์ง€ ์•Š์Œ 
str.slice(0, -1); // "Cats are common pets throughout the worl" 0๋ถ€ํ„ฐ str.length - 1์„ ํฌํ•จํ•˜์ง€ ์•Š์Œ
str.slice(-11, 33); // "t t"

beginIndex๋Š” str.length - 11 ๋ถ€ํ„ฐ์ธ 30์ด๊ณ  endIndex๋Š” 33์ด๋ฉฐ ํฌํ•จํ•˜์ง€ ์•Š์€ ๊ทธ ์•ž๊นŒ์ง€์ด๋‹ค. (30, 31, 32)

str.slice(30, -8); // "t t"

beginIndex๋Š” 33๋ถ€ํ„ฐ, endIndex๋Š” str.length - 8 ์ธ 33์ด๋ฉฐ ํฌํ•จ๋˜์ง€ ์•Š์€ ๊ทธ ์•ž๊นŒ์ง€์ด๋‹ค. (30, 31, 32)

str.slice(-5, -1); // "worl"

beginIndex๋Š” str.length - 5 ์ธ 36๋ถ€ํ„ฐ์ด๊ณ , endIndex๋Š” str.length - 1์ธ 40์ด๊ณ  ํฌํ•จํ•˜์ง€ ์•Š์€ ๊ทธ ์•ž๊นŒ์ง€์ด๋‹ค. (36, 37, 38, 39)

PreviousString.lastIndexOfNextstring.search

Last updated 5 years ago

Was this helpful?