Javascript ~ distinct JSON

這範例是把JSON裡的clubname給DISTINCT

Javascript
-------------------------------------------------------------------------------------
var xxxx = {"items":[{"id":"19","clubname":"Edison Bar"},{"id":"20","clubname":"Edison Bar"},{"id":"12","clubname":"Tatou"},{"id":"13","clubname":"Tatou"},{"id":"14","clubname":"GGYY"},{"id":"15","clubname":"Tatou"},{"id":"10","clubname":"Tatou"},{"id":"11","clubname":"Tatou"}]};


var cn = {};
$.each(xxxx.items, function() {
cn[this.clubname] = 1;
})

for(var xxx in cn) console.log(xxx);
-------------------------------------------------------------------------------------

output:
-------------------------------------------------------------------------------------
Edison Bar
Tatou
GGYY
-------------------------------------------------------------------------------------


感謝張搞大大XD
http://msp-story.blogspot.com/

沒有留言: