日期:2014-05-16 浏览次数:20313 次
/** *将数组分割成新的数组[二维数组] *@param myArray 需要分割的数组 *@param size 分割每个子数组的长度 */ function getNewArray(myArray,size){ var len=parseInt(myArray.length/size); var remain=myArray.length%size; var my_array=[],count=1,sot=remain>0?len+1:len; for ( var f = 1; f <=sot; f++) { var start=size*(f-1); var end=(f>len)?((f-1)*size+remain):f*size; var mylocates=myArray.slice(start,end); my_array.push(mylocates); } return my_array; }
var testArray=[3,324,5345,6546,134,5654,665]; testArray.sort(); alert(testArray.join(","));
var testArray=[3,324,5345,6546,134,5654,665]; testArray.sort(function(a,b){return a-b;}); alert(testArray.join(","));
var arr=[ [2,1,55,4], [5,3,22,3], [1,2,77,2], [9,4,33,5], ]; alert("默认按第一列排\n"+arr.sort().join("\n")); alert("现在按第三列排\n"+arr.sort(function(left,right){return left[2]>right[2]?1:-1}).join("\n")); alert("现在按第三列倒排\n"+arr.sort(function(left,right){return left[2]>right[2]?-1:1}).join("\n"));