Exemplos como: abaixo:
Copie o código do código da seguinte forma:
/**
* Exclua os elementos da matriz através do valor
*
* Valor misto @param Valor elementar
* Array @return
*/
Array.prototype.deleteValue = function (value) {
var i = 0;
para (eu nisso) {
if (este [i] == valor) quebra;
}
Retornar este.slice (0, i) .Concat (this.slice (parseint (i, 10) + 1));
}
// Exemplo
var teste = nova matriz (1,5,3,4,2);
// Saída 5
console.log (test.length);
// Exclua o elemento com um valor de 4
teste = test.deleteValue (4);
// saída [1, 5, 3, 2]
console.log (teste);
// saída 4
console.log (test.length);
/**
* Excluir elementos de matriz através de índices
*
* @param int int Índice Índice
* Array @return
*/
Array.prototype.deleteIndex = function (index) {
Retornar this.slice (0, índice) .CONCAT (this.slice (parseint (índice, 10) + 1));
}
// Exemplo
var teste = nova matriz (1,5,3,4,2);
// Saída 5
console.log (test.length);
// Exclua o elemento com indexação 1
teste = test.deleteIndex (1);
// saída [1, 3, 4, 2]
console.log (teste);
// saída 4
console.log (test.length);