728x90

slice()

slice()는 배열의 일부분을 선택하여 새로운 배열을 만든다.

arr.slice([begin[, end]])

begin

잘라낼 배열의 시작 index

 

end

잘라낼 배열의 종료 index

end index의 값은 잘라낼 배열에 포함되지 않는다.

end index가 생략되면, begin index부터 배열의 끝까지를 잘라낸다.

begin index나 end index가 음수면 배열 끝에서부터의 길이를 나타낸다.

 

예제

See the Pen Untitled by Kim Jae Ik (@doitdoik) on CodePen.

 

728x90

+ Recent posts