jQuery Utilities

$.each(object,function(name,value){}),用于遍历对象和数组。

1 <b>$.each( [0,1,2], function(i, n){
2   alert( "Item #" + i + ": " + n );
3 });
4 $.each( { name: "John", lang: "JS" }, function(i, n){
5   alert( "Name: " + i + ", Value: " + n );
6 });</b>

$.grep(array, callback, [invert] ),使用过滤函数过滤数组元素。如果 "invert" 为 false 或为设置,则函数返回数组中由过滤函数返回 true 的元素,当"invert" 为 true,则返回过滤函数中返回 false 的元素集。

1 <b>$.grep( [0,1,2], function(n,i){
2   return n > 0;
3 });
4 //return [1,2]
5 $.grep( [0,1,2], function(n,i){
6   return n > 0;
7 }, true);
8 //return [0]</b>

$.map(array, callback) 将一个数组中的元素转换到另一个数组中。

1 <b>$.map( [0,1,2], function(n){
2   return n + 4;
3 });
4 //return [4,5,6]</b>

$.merge(first, second)合并两个数组

1 <b>$.merge( [0,1,2], [2,3,4] )
2 //return [0,1,2,2,3,4]</b>

$.unique(array) 删除数组中重复元素

1 <b>$.unique([0,1,2,2]);
2 //return [2,1,0]</b>
$.trim(str) 去掉字符串起始和结尾的空格

$.makeArray(obj)将类数组对象转换为数组对象

$.inArray(value,array)确定第一个参数在数组中的位置,从0开始计数(如果没有找到则返回 -1 )

原文地址:https://www.cnblogs.com/shipeng22022/p/4614120.html