using unique() for array

using unique() for array

ansarigmbhansarigmbh Posts: 24Questions: 7Answers: 0

Hi

when I used this code:

table.column(1).data().unique(); 

The returned value was not an array that contains unique values. In this column I have an array for each cell.

[["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["1", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4"], ["4", "8"], ["1", "2", "4"], ["2", "4"], ["2", "4"], ["4", "16"], ["4", "16"], ["2", "4"], ["1", "4"], ["4", "16"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"], ["2", "4"]]

what should I do?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    The unique() method will compare the objects at the top level - so in Javascript ["1", "4"] !== ["1", "4"] hence why unique doesn't work for your use case.

    If you need to check if the inner arrays are unique, you would need to perform the loop check yourself.

    Allan

This discussion has been closed.