removing duplicates from html elements

前端 未结 6 1827
野趣味
野趣味 2020-12-21 17:49

what\'s the best way to remove the grapes duplicate from this? there are tons of ways of removing duplicates from simple arrays, but this would be an array with html element

6条回答
  •  [愿得一人]
    2020-12-21 18:36

    jsFiddle here: http://jsfiddle.net/THEtheChad/UKRwf/

    var found = {};
    var $unique_fruits = $('.fruit').filter(function(){
       var data = this.innerHTML.trim();
    
       if(!found.hasOwnProperty(data)) return found[data] = true;
    });
    

提交回复
热议问题