-
|
Array.prototyle 메서드 |
Beta Was this translation helpful? Give feedback.
Answered by
Lv1GoM
Feb 21, 2024
Replies: 1 comment
-
Array.prototype 메서드Array.prototype은 JavaScript 배열 객체의 프로토타입 객체를 나타낸다. 배열의 모든 인스턴스는 이 프로토타입을 상속받아서 배열 관련 메서드와 프로퍼티를 사용할 수 있다. const array = Array.prototype.slice.call(arrayLikeObj);
console.log(array); // ['apple', 'banana', 'orange']
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Lv1GoM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Array.prototype 메서드
Array.prototype은 JavaScript 배열 객체의 프로토타입 객체를 나타낸다. 배열의 모든 인스턴스는 이 프로토타입을 상속받아서 배열 관련 메서드와 프로퍼티를 사용할 수 있다.
[filter, map, reduce, slice, splice...]Array.prototype.slice메서드slice 메서드는 배열의 일부분을 추출하여 새로운 배열을 반환한다. 이 메서드는 두 개의 인자를 받을 수 있는데, 첫 번째는 추출을 시작할 인덱스이고, 두 번째는 추출을 끝낼 인덱스이다.
.call(arrayLikeObj)JavaScript의 모든 함수는this값을 가지며,call메서드를 사용하면 함수의this값을 특정 값으로 설정할 수 있다. 여기서는 slice 메서드를 호출하는데,this를arrayLikeObj로 설정하여 유사 배열 객체를 대상으로slice메서드를 실행한다.slice메서드를 호출하면서this를arrayLikeObj로 설정하면,slice메서드는arrayLikeObj를 배열로 간주하여 배열의 메서드처럼 동작하게 된다. 결과적으로 새로운 배열이 반…