Remove duplicate objects from an array using javascript

后端 未结 9 1879
野性不改
野性不改 2020-12-02 21:21

I am trying to figure out an efficient way to remove objects that are duplicates from an array and looking for the most efficient answer. I looked around the internet everyt

9条回答
  •  伪装坚强ぢ
    2020-12-02 21:50

    function remove_duplicates(objectsArray) {
        var arr = [], collection = []; 
        $.each(objectsArray, function (index, value) {
            if ($.inArray(value.id, arr) == -1) { 
                arr.push(value.id);
                collection.push(value);
            }
        });
        return collection;
    }
    

提交回复
热议问题