1.$.map (Array,callback (Element,index))
For each element in an array of arrays, call the callback () function, and eventually return a new array, the original array unchanged.
Case: Double the value of an element with an index greater than 3 in an array, the remaining value is unchanged, and a new array is returned
var arr = [1, 2, 4, 6, 3, 7, 8];
var newArr = $.map (arr, function (ele, index) {
if (Index > 3) {
return ele * 2;
}
else {
return ele;
}
});
alert (NEWARR);
2.$.each (ARRAY,FN)//Iterate through the array, return false to eject the loop
It is used primarily to iterate through an array, not to modify an array, or to have no problem with an ordinary array or a "key-value pair" array.
This can be used directly in each function to represent the value of the current element.
Key-value pairs
var dic = {"name": "Xiaoming", "Age": 23};
$.each (DIC, function (k,v) {
Alert (k + ' = = = ' +v);
//});
var arr = [1, 2, 3, 4, 5, 6];
$.each (arr, function (k, v) {
Alert (k + "= = =" +v);
});
Two methods of traversal in jquery