Home > Web Front-end > JS Tutorial > Summary of JQuery's tool functions for manipulating Javascript objects and arrays_jquery

Summary of JQuery's tool functions for manipulating Javascript objects and arrays_jquery

WBOY
Release: 2016-05-16 18:36:01
Original
854 people have browsed it

JQuery functions for operating non-collection arrays
$.trim(value)
This function is very simple, removing any leading or trailing whitespace characters from value. A whitespace character is any character that matches a Javascript regular expression s. Including spaces, page feeds, line feeds, carriage returns, tabs, vertical indicators, etc.

$.each(container, callback)
Iterate over each item of the container and call the callback function callback for each item.
container can be an object or an array. If it is a js object, each of its properties is iterated; if it is an array, each of its elements is iterated.
callback callback function. Called once for each iteration. The first parameter is the subscript of the array element or the name of the object attribute, and the second parameter is the value of the corresponding array element or object attribute. The function context called (this) is the same as the second function.

Copy code The code is as follows:

var obj = {a:1, b:2, c:3};
$.each(obj, function(name, value){
alert(name ':' value);
});

$. extend(target, source1, source2, ..., sourcen)
Extend the target object with the properties of the source1...n object. The return value is the expanded object.
Copy code The code is as follows:

var target = { a:1, b:2, c:3 };
var source1 = { c:4, d:5, e:6 };
var source2 = { e:7, f:8, g:9 };
$. extend(target, source1, source2);
$.each(target, function(name, value){
alert(name ':' value);
});

The returned value is {a:1, b:2, c:4, d:5, e:7, f:8, g:9}

$.getScript(url, callback)
Dynamic loading of js scripts. And call the callback function when the script is successfully fetched.

$.noConflict
Avoid $alias conflicts. Once the $.noConflict function is executed, it must be called with the jQuery name.

JQuery array processing function
$.each(container, callback)
This function can also iterate arrays. Specific instructions are above.

$.grep(array, callback, invert)
Traverse the passed array and call the swap function for each element. The return value of the callback function determines whether to collect the current elements into a new array, and the new array is used as the return value of $.grep. The callback function needs to return a bool type value. If invert is omitted or false, elements whose callback function returns TRUE are collected into the return result. If invert is true, the elements whose callback function returns false are collected into the return result.

$.map(array, callback)
Traverse the array, call the callback function for each element, and collect the return value of the callback function into a new array and return it.

$.inArray(value,array)
Returns the index of the first occurrence of the passed value in the array. If the value does not exist in the array, -1 is returned.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template