I have two json objects
$scope.car1={"Sedan":{"Audi":["A4","A3"]},"Hatchback":{"Maruthi":["Swift"]}};
$scope.car2={"Hatchback":{"Maruthi":["Swift"]},"Sedan":{"Audi":["A3","A4"]}};
I want to pare these two objects. I tried the following code:
var a=angular.equals($scope.car1,$scope.car2);
Since angular.equals
do a deep parison it also care about the order of data. Is there any way to pare objects regardless of the order?
I have two json objects
$scope.car1={"Sedan":{"Audi":["A4","A3"]},"Hatchback":{"Maruthi":["Swift"]}};
$scope.car2={"Hatchback":{"Maruthi":["Swift"]},"Sedan":{"Audi":["A3","A4"]}};
I want to pare these two objects. I tried the following code:
var a=angular.equals($scope.car1,$scope.car2);
Since angular.equals
do a deep parison it also care about the order of data. Is there any way to pare objects regardless of the order?
2 Answers
Reset to default 2'Objects' do not have an order. angular.equals
will pare values using their keys.
Implement a custom "recursive equalizer" that distinct if array is associative or not:
for associative => equalize keys,
for arrays => sort array & equalize elements.
written the function myEqual()
at this plunker