Array.prototype.remove3 = function () {
this.forEach(function (a, i) {
if (a == 3) {
this.splice(i, 1);
}
});
};
var arr = [1, 2, 3];
arr.remove3();
console.log(arr);
라고 코드를 짰는데 TypeError: this.splice is not a function 에러가 나오네요.
정답을 보니까 for문으로 하셨던데 foreach로 했을 때 오류가 나는 이유가 뭘까요?