Deletes the first and last null characters of a string.: $. Trim ()
Similar functions are provided in many advanced languages, and the jQuery Class Library also provides such functions. Usage: $. trim (value) removes the first and last blank characters from the input string and returns the result.
Perform an iteration on attributes and integration:
You can use the following method to operate 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 each entry of the input container and call the incoming callback function for each entry.
This function can iterate arrays or objects 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 ){...});
Filter Arrays:
Traversing arrays to search for elements that match specific standards is a frequent requirement for applications that process large amounts of data. jQuery provides the $. grep () function to implement this function.
$. Grep (array, callback, invert) traverses the passed array and calls the callback function for each element. The Return Value of the callback function determines whether to collect the current element into the new array (the new array is returned as the value of the $. grep () function ).
To filter an array, obtain 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:
$. InArray (value, array) returns the subscript when the input value first appears in the array.
Var index = $. inArray (2, [, 5]); the result is that 1 is returned and sent to the index variable.