angular.equals for JSON Object Comparison

less than 1 minute read

TIL that angular has an “equals” method that does a deep comparison between objects to determine equality.


var object1 = {'1': 'hello', '2': 100};
var object2 = {'2': 100, '1': 'hello'};

object1 === object2; // evaluates to false

angular.equals(object1, object2); // evaluates to true

I needed to do a deep compare between two JSON objects to see if they contained equivalent values, and was about to write my own deep compare when I stumbled upon this built-in. Way to go angular!

Leave a Comment