Delete string trailing null character: $.trim ()
Similar functions are provided in many advanced languages, and the jquery class library provides such functions as well. Specific usage: $.trim (value) deletes the trailing and ending whitespace characters from the passed-in string and returns the result.
To iterate over attributes and collections:
The following methods can be used to manipulate arrays and objects in javascript:
var anarray = [' One ', ' two ', ' three '];
for (var n = 0; n < anarray.length n++) {...}
var anobject = {one:1, two:2, three:3};
For (var p in AnObject) {...}
In jquery, $.each (Container,callback) is provided to iterate over each item of the incoming container, calling the incoming callback function for each item.
This function can iterate over an algebraic group or object in the same format:
var anarray = [' One ', ' two ', ' three '];
$.each (Anarray,function (n,value) {...});
var anobject = {one:1, two:2, three:3};
$.each (Anobject,function (name,value) {...});
To filter an array:
Traversing an array to find elements that match a particular standard is a frequent requirement for processing large amounts of data, and jquery provides the $.grep () function to implement such a function.
$.grep (Array,callback,invert) traverses the array passed in and invokes the callback function for each element. The return value of the callback function determines whether the current element is collected into a new array (the new array is returned as the value of the $.grep () function).
If you want to filter an array, get all values greater than 100:
var bignumber = $.grep (originalarray,function (value) {return value > 100;});
Whether the array contains a specific value or a small value in the array for a particular value:
$.inarray (Value,array) returns the subscript for the first occurrence of the passed value in the array.
var index = $.inarray (2,[1,2,3,4,5]); The result is to return the subscript value of 1 and assign to the index variable.