아래 : 아래 :
다음과 같이 코드 코드를 복사하십시오.
/**
* 값을 통해 배열 요소를 삭제하십시오
*
* @param 혼합 값 원소 값
* @return 배열
*/
Array.prototype.deleteValue = function (value) {
var i = 0;
(나는 이것으로) {
if (이 [i] == value) 브레이크;
}
replay.slice (0, i) .concat (this.slice (parseint (i, 10) + 1));
}
// 예
var test = 새로운 배열 (1,5,3,4,2);
// 출력 5
Console.log (Test.Length);
// 값이 4 인 요소를 삭제합니다
test = test.deleteValue (4);
// 출력 [1, 5, 3, 2]
Console.log (테스트);
// 출력 4
Console.log (Test.Length);
/**
* 인덱스를 통해 배열 요소를 삭제합니다
*
* @param int Index Index
* @return 배열
*/
Array.prototype.deleteIndex = function (index) {
retract.slice (0, index) .concat (this.slice (parseint (parseint (index, 10) + 1));
}
// 예
var test = 새로운 배열 (1,5,3,4,2);
// 출력 5
Console.log (Test.Length);
// 인덱싱으로 요소를 삭제합니다 1
test = test.deleteindex (1);
// 출력 [1, 3, 4, 2]
Console.log (테스트);
// 출력 4
Console.log (Test.Length);