Removing duplicate strings using javascript

后端 未结 6 1843
耶瑟儿~
耶瑟儿~ 2021-01-15 00:27

I have an array of 800 sentences. I want to remove all duplicates (sentences that have the same exact words, but in different order) from the array. So for example \"this is

6条回答
  •  伪装坚强ぢ
    2021-01-15 00:57

    Here's something to try. I didn't test its performance on large arrays, but I think it should be ok. No jQuery needed.

    function removeDuplicates(array)
    {
        var new_array = [];
        for(var i=0; i

    Use it like this:

    var a = ["this is a name", "name is this a", "this name is a", "hello there"];
    var clean_array = removeDuplicates(a);
    alert(clean_array); // outputs: a is name this,hello there
    

提交回复
热议问题