發表文章

目前顯示的是 6月, 2015的文章

[javascript] 二維陣列的排序

陣列格式 var a = [ {name:'hdj', filename:20140930174726.jpg}, {name:'yim', filename:1_title.jpg}, {name:'hdq', filename:20150930174726.jpg}, {name:'rrr', filename:3_title.jpg}, {name:'ddd', filename:2_title.jpg}, ]; 希望根據 filename 來進行排序,可以使用底下的 function function listSortBy ( arr , field , order ){     var refer = [], newrefer = [], comp_arr =[], result =[];     var order = order == ' asc' ? ' asc ' : 'desc ' , index ;     for ( i = 0 ; i < arr . length ; i ++){         // 1_title.jpg 20140930174726.jpg         var delExt = arr [ i ][ field ]. split ( "." );         // 1_title 20140930174726         var name    = delExt [ 0 ]. split ( "_" );         if ( typeof ( name [ 1 ]) == 'undefined' ) {             refer [ delExt [ 0 ]] = i ;             comp_arr [ i ]       = delExt [ 0 ];         } else {             refe