str.slice(beginIndex[, endIndex])
인자
beginIndex
추출 시작점인 0부터 시작하는 인덱스입니다. 만약 음수라면, beginIndex는
strLength(문자열 길이) + beginIndex
로 취급됩니다. (예를 들어 beginIndex
가 -3이면 시작점은 strLength - 3
).만약
beginIndex
가 strLength
보다 크거나 같은 경우, slice()
는 빈 문자열을 반환합니다.endIndex
Optional0부터 시작하는 추출 종료점 인덱스로 그 직전까지 추출됩니다. 인덱스 위치의 문자는 추출에 포함되지 않습니다.
만약
endIndex
가 생략된다면, silce()
는 문자열 마지막까지 추출합니다. 만약 음수라면, endIndex는 strLength(문자열 길이) + endIndex
로 취급됩니다(예를 들어 endIndex
가 -3이면 종료점은 strLength - 3
).const str = 'The quick brown fox jumps over the lazy dog.'; console.log(str.slice(31)); // expected output: "the lazy dog." console.log(str.slice(4, 19)); // expected output: "quick brown fox" console.log(str.slice(-4)); // 뒤에서 4글자만 추출 // expected output: "dog." console.log(str.slice(-9, -5)); // 뒤에서 9번째 글자에서 뒤에서 6번째까지 추출 // -9부터 ~ (-5-1)까지 // expected output: "lazy"