JQuery tool functions for Javascript objects and Arrays

Source: Internet
Author: User

JQuery provides many useful tool functions. These functions are mainly divided into two types: functions that operate the set array and non-set array functions.

JQuery operations on non-set array Functions

$. Trim (value)

This function is simple. Remove any leading or trailing white spaces from the value. The white space character is any character that matches the Javascript Regular Expression \ s. Including space, page feed, line feed, carriage return, tab, and vertical indicator.

$. Each (container, callback)

Iterates each item of the container and calls the callback function callback for each item.

The container can be an object or an array. If it is a js object, each attribute is iterated; if it is an array, each element is iterated.

Callback function. For each iteration. The first parameter indicates the subscript of the array element or the name of the object attribute. The second parameter indicates the value of the corresponding array element or object attribute. The context of the called function (this) is the same as that of the second function.

Var obj = {a: 1, B: 2, c: 3 };
$. Each (obj, function (name, value ){
Alert (name + ':' + value );
});

$. Extend (target, source1, source2,..., sourcen)

Use the attributes of the source1.. n object to extend the target object. The returned value is an extended object.

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 values are {a: 1, B: 2, c: 4, d: 5, e: 7, f: 8, g: 9}

$. GetScript (url, callback)

Dynamically load js scripts. The callback function is called when the script is obtained successfully.

$. NoConflict

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

JQuery processes array Functions

$. Each (container, callback)

This function can also iterate the array. The details are described above.

$. Grep (array, callback, invert)

Traverses the input array and calls the reconciliation 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 used as the return value of $. grep. The callback function must return a value of the bool type. If invert is omitted or false, elements returned by the callback function to TRUE are collected to the returned results. If invert is true, the elements that the callback function returns false are collected to the returned results.

$. Map (array, callback)

Traverse the array, call the callback function for each element, and collect the return values of the callback function into the new array.

$. InArray (value, array)

Returns the subscript that appears for the first time in the array. If the value does not exist in the array,-1 is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.