Home >Web Front-end >JS Tutorial >Methods for operating arrays based on jQuery_jquery

Methods for operating arrays based on jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 17:36:431045browse

jQuery provides two functions:

1.$.map(array,callback(element,index));

For each element in the array, call the callback() function, and finally return a new array, the original array remains unchanged

For example:

                                                                                                                                                                                                       What comes back is a new array
               return value * 2;
})

2. $.each(array,fn);

Mainly used to traverse arrays without modifying the array. It can be traversed for ordinary arrays or "key-value arrays".

This can be used directly in each function to represent the value of the current element.

For example: Get the selected item in the checkbox

                                                                                                                                        

$(function () {

var arr = [];

                                                                                                                                                      

                                                                                                                                                                         ​ 

arr[key] = value.text();

                                                                                                                        

                var lengtha = $('input[type=checkbox][checked=checked]').length; 🎜>

                                                                                                    

})

Statement:
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