Next, let's take a look at some array methods implemented by chrome/15.
Bytes ---------------------------------------------------------------------------------------------
Concat
Join: concatenates an array.
Pop: The out-of-stack operation. Note that this operation also modifies the original array in place.
Push: the inbound operation. Note that this operation is also used to modify the original array.
Reverse: inverted array. Note that this is also the original array modified in place.
Shift: Team-out operation. Note that this operation is also used to modify the original array.
Unshift: insert an item in the array header, followed by this move
Slice: truncates a part of an array. A common operation is to use this method to convert an array of classes to a real array.
Splice: Modify the array, which can be used to insert new items. Note that this is also the local modification of the original array.
Sort: array sorting. Note that this is also used to modify the original array.
ToLocaleString: returns the local string of the array. Generally, it is a comma (,).
ToString: returns the string format of the array. Generally, it is a comma.
Bytes ---------------------------------------------------------------------------------------------
IsArray: determines whether a variable is an Array. Note that this is a static method, called in the form of Array. isArray ()
Bytes ---------------------------------------------------------------------------------------------
Every: determines whether all items in an array meet the conditions. If all the items meet the conditions, true is returned; otherwise, false is returned.
Some: this can be associated with every. If every is set to true, true is returned. If some is set to true, true is returned.
Filter: filters out the items that meet the conditions from the array according to the given conditions, and then returns the items as a new array. Otherwise, null is returned.
ForEach: performs a given operation on each item in the array.
IndexOf: returns the first position of a given item in the array (starting from 0 subscript)
LastIndexOf: opposite to indexOf
Map: Execute the given operation for each item in the array and return the modified array.
Reduce: reduce (func, init) func is a binary function that acts func on the elements of the seq sequence, each carrying a pair (previous results and elements of the next sequence ), continuously apply the existing results and the next value to the subsequent results, and finally reduce our sequence into a single return value.
ReduceRight: reduce implementation from right to left
Bytes ---------------------------------------------------------------------------------------------
When we implement our own small library or some tools, we can also slightly expand it.
Copy codeThe Code is as follows:
Object. prototype. extend = function (src ){
For (var I in src ){
This [I] = src [I];
}
}
Array. extend ({
ToArray: function (arrayLike ){
Try {
Return []. slice. call (arrayLike );
} Catch (ex ){
Var ret = [];
For (var I = 0, len = arrayLike. length; I <len; I ++ ){
Ret. push (arrayLike [I]);
}
}
},
IsArray: (Array. isArray )? Array. isArray: function (ele ){
Return ele. constructor = Array;
}
})
Array. prototype. extend (function (){
Var each = Array. prototype. forEach | function (fn, obj ){
For (var I = 0, len = this. length; I <len; I ++ ){
Fn. call (obj, this [I]);
}
};
Var filter = Array. prototype. filter | function (fn, obj ){
Var result = [];
For (var I = 0, len = this. length; I <len; I ++ ){
If (fn. call (obj, this [I]) {
Result. push (this [I]);
}
}
Return result;
};
Var every = Array. prototype. every | function (fn, obj ){
For (var I = 0, len = this. length; I <len; I ++ ){
If (! Fn. call (obj, this [I]) {
Return false;
}
}
Return true;
};
Var some = Array. prototype. some | function (fn, obj ){
For (var I = 0, len = this. length; I <len; I ++ ){
If (fn. call (obj, this [I]) {
Return true;
}
}
Return false;
};
Var indexOf = Array. prototype. indexOf | function (dest ){
For (var I = 0; I <this. length; I ++ ){
If (dest = this [I]) {
Return I;
}
}
Return-1;
};
Var map = Array. prototype. map | function (fn, obj ){
Var result = [];
For (var I = 0, len = this. length; I <len; I ++ ){
Result. push (fn. call (obj, this [I]);
}
Return result;
};
Var reduce = Array. prototype. reduce | function (fn, init ){
Var result = init | this [0];
For (var I = 0; I <this. length; I ++ ){
Result = fn (result, this [I]);
}
Return result;
}
Return {
Map: map,
Each: each,
Some: some,
Every: every,
Filter: filter,
IndexOf: indexOf,
Reduce: reduce
}
})())
The following is a small example of setting the li content for the specified ul:
Copy codeThe Code is as follows:
<Ul id = "test">
<Li> </li>
<Li> </li>
<Li> </li>
</Ul>
<Script type = "text/javascript">
Array. prototype. slice. call (document. getElementById ('test'). getElementsByTagName ('lil'), 0). each (function (li ){
Li. innerHTML = 'test upload ';
})
</Script>