grep
grep() method is used to filter array elements
grep(array,callback,invert)
array: array to be filtered;
callback: process each element in the array elements, and filter the elements. This function contains two parameters, the first is the value of the current array element, and the other is the subscript of the current array element, that is, the element index value. This function should return a boolean value. Alternatively, this function can be set to a string, and when set to a string, is treated as a "lambda-form" (short form?), where a represents the array element and i represents the element index value. For example, "a > 0" represents "function(a){ return a > 0; }"
invert: Boolean optional, default value false, value is true or false, if "invert" is false or If set, the function returns the elements in the array that are returned true by the filter function. When "invert" is true, the set of elements that are returned false by the filter function is returned
< script type="text/javascript">
$().ready(
function(){
var array = [1,2,3,4,5,6,7,8,9 | ; I & lt; Filterary.Length; I) {
Alert (Filteraray [i]);
}
for (key in Filteraray) {
Alert (Filteraray [Key]);
}
}
);
each
How to use each
is available in jQuery An each method is very comfortable to use. You don’t need to write a for loop like before. There are many uses of each method in the jQuery source code.
In fact, the each method in jQuery is implemented through the call method in js.
Copy code
$().ready(
function(){
var anObject = {one:1,two:2,three:3};//For json array each
$.each(anObject,function(name,value) {
alert(name);
alert(value );
});
var anArray = ['one','two','three'];
$.each(anArray,function(n,value){
alert(n );
; >inArray
jQuery.isArray(obj) is new in jQuery 1.3. Tests whether the object is an array. Return value: Boolean
Parameters: objObject An object used to test whether it is an array
Example: Detect whether it is an array
Copy code
The code is as follows:
map
map() passes each element into the current matching set through the function and generates a new jQuery object containing the return value.
Since the return value is an array encapsulated by jQuery, use get() to process the returned object to get the underlying array. The
.map() method is particularly useful for getting or setting the value of a set of elements. Consider the following form with a series of checkboxes
Traverse the json object:
Copy code
The code is as follows: <script></div>var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; <div class="codebody" id="code85758">for(var i=0,l=json.length;i<l;i ){<br> for(var key in json[i]){<br> alert(key ':' json[i] [key]);<br> }<br>}<br></script>
Traversing json objects
has the following json objects:
Copy code
The code is as follows:var obj ={"name":"Feng Juan" ,"password":"123456","department":"Technical Department","sex":"Female","old":30};
Traversal method:
for(var p in obj){
str = str obj[p] ',';
return str;
}