A method based on the operation of the array in jquery _jquery

Source: Internet
Author: User

Two functions are available in jquery:

1.$.map (Array,callback (Element,index));

For each element in the array, call the callback () function, eventually returning a new array, the original array unchanged

For example:

$ (function () {
var arrint = [1, 3, 5, 79];
var B = $.map (Arrint, function (value, key, a) {//map returns a new array
return value * 2;
});

})

2. $.each (ARRAY,FN);

The main use is to traverse the array, not modify the array, for ordinary arrays or "key-value arrays" can be traversed.

You can use this directly in each function to represent the value of the current element.

For example: Gets the selected item in the checkbox

<script type= "Text/javascript" >

$ (function () {

var arr = [];

$ (' input[type=checkbox] '). Click (function () {

$ (' input[type=checbox]:checked '). each (function (key, value) {

Arr[key] = Value.text ();

});

var Lengtha = $ (' input[type=checkbox][checked=checked] '). length; $ (' #spMsg '). Text (' total ' + Lengtha + ' is selected respectively: ' + arr ');

})

})

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.