Comparing 2 exact objects

Is there a way to compare 2 objects exactly, without having to loop through each item inside the object.

For example…

House

Rooms
Living
Bedroom1
Bedroom2
Materials
Brick
Date
2022
May
23

Is the exact same as the following below

House

Rooms
Living
Bedroom1
Bedroom2
Materials
Brick
Date
2022
May
23

It should return true…

But if just 1 thing is different it should return false.

I’m just wondering if there’s a quick way to check that the entire 2 objects are exactly the same in every way without being required to loop through every part of each object?

Thanks

1 Like

you can compare them as jSON strings. But as muneer notes below, the model key/value pair Order must match across objects.

4 Likes

No there isn’t.

The JSON comparison will work only if the two objects having all properties in the same exact order. If the properties are not in the same order the JSON comparison will fail.

The only certain way is to loop through the properties doing text comparison of the values.

3 Likes

I ended up solving this by getting json from object, adding each j to a list, filtering anything I didn’t want, and then comparing it to a similar filtered list.

If list 1 contained j from list 2 then I acted on it and flipped it back to an object.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.