how to get distinct values from json in jquery

后端 未结 3 698
走了就别回头了
走了就别回头了 2020-12-31 15:13

I\'ve got a jquery json request and in that json data I want to be able to sort by unique values. so I have

{
  \"people\": [{
        \"pbid\": \"626\",
           


        
3条回答
  •  情深已故
    2020-12-31 15:39

    Here's my take:

    function getUniqueBirthdays(data){
        var birthdays = [];
        $.each(data.people, function(){
            if ($.inArray(this.birthDate,birthdays) === -1) {
                birthdays.push(this.birthDate);
            }
        });
        return birthdays.sort();
    }
    

提交回复
热议问题