Array. prototype. del = function (n)
{
If (n <0) return this;
Return this. slice (0, n). concat (this. slice (n + 1, this. length ));
}
// Shuffling the Array
Array. prototype. random = function ()
{
Var nr = [], me = this, t;
While (me. length> 0)
{
Nr [nr. length] = me [t = Math. floor (Math. random () * me. length)];
Me = me. del (t );
}
Return nr;
}
// Sort the number Array
Array. prototype. sortNum = function (f)
{
If (! F) f = 0;
If (f = 1) return this. sort (function (a, B) {return B-;});
Return this. sort (function (a, B) {return a-B ;});
}
// Obtain the numeric entry of the number Array
Array. prototype. getMax = function ()
{
Return this. sortNum (1) [0];
}
// Obtain the minimum entry of the number Array
Array. prototype. getMin = function ()
{
Return this. sortNum (0) [0];
}
// The position where the specified Element value appears for the first time in the array
Array. prototype. indexOf = function (o)
{
For (var I = 0; I <this. length; I ++) if (this [I] = o) return I;
Return-1;
}
// Remove repeated items from the array
Array. prototype. removeRepeat = function ()
{
This. sort ();
Var rs = [];
Var cr = false;
For (var I = 0; I <this. length; I ++)
{
If (! Cr) cr = this [I];
Else if (cr = this [I]) rs [rs. length] = I;
Else cr = this [I];
}
Var re = this;
For (var I = rs. length-1; I> = 0; I --) re = re. del (rs [I]);
Return re;
}
Example:
Var arr = ["ni", "wo", "ta"];
Delete "wo" from the array"
Var newArr = arr. del (1 );
Returns the position where "me" appears for the first time in the array. If not,-1 is returned.
Var strPos = arr. indexOf ("me ");