0

I have this function is which I use lodash to check if 2 objects are the same.

private checkForChanges(): boolean {
    if (_.isEqual(this.definitionDetails, this.originalDetails) === true) {
        return false;
    } else {
        return true;
    }
}

I was wondering if the is a way to print out the properties which are different from eachother (incase the objects do not equal eachother)

i'm using both lodash and JQuery incase it helps

Liam
  • 27,717
  • 28
  • 128
  • 190
Nicolas
  • 4,526
  • 17
  • 50
  • 87

2 Answers2

0

There is no easy way because of the variety of possibilities for the comparison. If you check out the lodash source code, you will have an idea.

But, if you know what you are comparing, you may simplify the task. For example, the comparison is always between plain, shallow objects. There are some ideas in How to determine equality for two JavaScript objects? and Object comparison in JavaScript.

Extra note: there is no need for the if if you only need to return the result.

private checkForChanges(): boolean {
    return !_.isEqual(this.definitionDetails, this.originalDetails);
}
Rodris
  • 2,603
  • 1
  • 17
  • 25
-1

https://lodash.com/docs/#isEqual no need check true in if condition lodash will return true/false

 private checkForChanges(): boolean {
    if (_.isEqual(this.definitionDetails, this.originalDetails)) {
        return false;
    } else {
        return true;
    }
 }
Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31