0andme.github.io
0andme gitHub

String.slice()

문자열 일부 추출하기
April 19, 2022
  1. js

String.prototype.slice()

const newStr = str.slice(start, end)

문자열의 start부터 end-1까지의 문자열을 반환한다. 원본 문자열은 훼손되지 않는다.

✤ 기본 예제들
const str = "The quick brown fox jumps over the lazy dog."
console.log(str.slice(31)) //  "the lazy dog."
console.log(str.slice(4, 19)) // "quick brown fox"
console.log(str.slice(-4)) // "dog."
console.log(str.slice(-9, -5)) //  "lazy"
console.log(str) // "The quick brown fox jumps over the lazy dog."

공식 문서


Profile picture