JQuery learns 7 JavaScript objects and set functions

Source: Internet
Author: User

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.

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.