Search code examples
jquerysapui5

jQuery.sap.equal compare ordering


I'm comparing two objects (nested objects) using jQuery.sap.equal:
these objects include nested tables.
They both contain same values but not the same order and jQuery.sap.equal returns false. Is there a way to make it ignore the order?
Thanks!

example :

jQuery.sap.equal(
[
  { a: "b" },
  { c: "d" }
],
[
  { c: "d" },
  { a: "b" }
]) 
returns false

Solution

  • As mentioned in the API of jQuery.sap.equal,

    Compares the two given values for equality, especially takes care not to compare arrays and objects by reference, but compares their content. Note: function does not work with comparing XML objects.

    If you compare objects it will work but you have to handle for arrays.

    For Objects:

    jQuery.sap.equal(
     {
       x : { a: "b" },
       y : { c: "d" }
     },
    {
      y : { c: "d" },
      x : { a: "b" }
    });
    

    will return true