关键方法:sort()用于对数组的元素进行排序。
return a.num-b.num是升序;
return b.num-a.num;是降序
writeln在输出后面加\n,在文档里是换行,在html里是解释称空格。
$.post("json.json",function(data){
               data.sort(function(a,b){return a.num-b.num;});
               for(var i=0;i<data.length;i++){
                    var nums=data[i].num;
                    document.writeln(nums);
               }
          },"json")


json数据:
[
     {
     "num":"5"
     },
     {
       "num":"1"
     },

     {
     "num":"3"
     },
     {
       "num":"2"
     }
]

 

相关文章:

  • 2021-11-06
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2021-07-10
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案