84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
有一组json数据在进行for循环插入到dom时,
var tt = data.serach_house_price;//json数据 var html3 = ''; for(var i in tt) { html3 +='
输出结果如图所示,最后一个key循环到第一个位置了,如何对它们按大小进行重新排序呢?
How to use js to sort json data key values? -PHP Chinese website Q&A-How to use js to sort json data key values? -PHP Chinese website Q&A
Let’s take a look and learn.
var tt = { '0-40': '40万以下', '40-60': '40-60万', '60-80': '60-80万', '80-100': '80-100万', '100-150': '100-150万', '150-200': '150-200万', '200-300': '200-300万', '300-400': '300-400万', '400': '400万以上', } var sortKeys = Object.keys(tt).sort(function(i1,i2){ return i2.split('-')[0] - i1.split('-')[0] }); var html3 = ''; for(var i=0, len=sortKeys.length; i'+tt[sortKeys[i]]+'\n'; } console.log(html3);
这样看看满足吗?
How to use js to sort json data key values? -PHP Chinese website Q&A-How to use js to sort json data key values? -PHP Chinese website Q&A
Let’s take a look and learn.
这样看看满足吗?