What is the best method for comparing two JSON objects in AngularJS?

I am working with two JSON objects.

 $scope.car1={"Sedan":{"Audi":["A4","A3"]},"Hatchback":{"Maruthi":["Swift"]}}; 
  $scope.car2={"Hatchback":{"Maruthi":["Swift"]},"Sedan":{"Audi":["A3","A4"]}}; 

I have attempted to compare these two objects using the code below:

var a=angular.equals($scope.car1,$scope.car2);

Although angular.equals provides a deep comparison, it takes into consideration the order of data as well. I am looking for a method to compare objects without considering the order. Is there any other way to achieve this?

Answer №1

'Items' do not follow a specific sequence. The function angular.equals evaluates values based on their corresponding keys.

Answer №2

Create a unique "recursive equalizer" function that can determine whether an array is associative or not:
If it's associative, equalize the keys, if it's an array, sort the elements & equalize them.

The custom function myEqual() has been implemented and can be found on this plunker

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to successfully transfer parameters from AJAX to PHP

I successfully utilized Jquery UI to update the position of my table. Now, I am trying to pass a parameter from AJAX to PHP in order to update my database with the current table position. However, I encountered an issue where I receive a TypeError: data=nu ...

Animating with CSS3 triggered by JavaScript

Can you help me with an issue I'm having? When attempting to rotate the blue square using a function, it only works once. After that, the page needs to be reloaded in order for the rotation function to work again. Additionally, after rotating 120 degr ...

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Unleashing the Power of v-model in Vue.js: A Comprehensive Guide to Referencing Input

I am a beginner in vue.js and I am currently facing an issue with making a get request from a field that has a v-model="embed.url" after pasting a link. The paste event works fine, but I'm struggling to reference the input with v-model="embed.url" and ...

Ajax: Understanding the Difference Between Definition and Implementation (Comparing XML, JSON, and Alternatives)

Do you prefer using AJAX, which stands for Asynchronous JavaScript And XML, or do you lean towards JSON as an alternative? Personally, I have found JSON to be smaller, easier, and more efficient for transmitting data. Which technology do you use to communi ...

Implement feature to enable selection using jQuery

I have a question about implementing an <option value="fiat">Fiat</option>"> element into a dropdown list using jQuery. I've tried the code below and encountered some issues. When I click the button, I want to add the <option value= ...

What is the best way to generate the message dynamically?

I have implemented the react-intl package for translation purposes in my project. Users have the option to choose between Spanish and English languages, with Spanish being the default language. When a user switches to English, all text should be dynamicall ...

The jquery live click event is not functioning properly on iPad devices

I am experiencing an issue with a webpage that has the following code to bind click events <script type="text/javascript"> $(".groupLbl").live("click", function(e) { var $target = $(e.currentTarget); ..... $.getJSON("/somelink.js ...

Utilize and store images based on the individual user's preferences with PlayCanvas

Currently, I am immersed in a PlayCanvas endeavor where I am trying to render specific objects with textures of my choice. The main issue arises when I come across the config.json file in the PlayCanvas build. Within this file, there is a designated path ...

Exploring the Capabilities of Drag-and-Drop Functionality in jsTree and DataTables

Is it possible to copy nodes from a jsTree that I've dragged to a cell in a DataTable? I'm struggling with getting this functionality to work. Any suggestions on how to achieve this? I am not seeing any alerts appear. This is the HTML code: &l ...

Using Json.Net to deserialize intricate data structures

I am facing an issue with deserializing JSON for the following classes: public class Players:List<Player> { } public class Player { public Player() { PlayerTeam = new Team(); } public int PlayerId { get; set; } public T ...

Error occurs in ASP.NET AJAX Control Toolkit while uploading files within Scriptresource.axd

I recently encountered an issue with my AJAX Control Toolkit File Upload (Version 15.1.4) in my ASP.Net Web Application. Up until this week, it was functioning perfectly fine. However, starting yesterday, I started receiving a JavaScript error right after ...

Acquiring the Item ID following a successful upload via REST to a SharePoint 2013 Online Document Library

Could someone assist me in understanding how to link these functions together? I am able to upload files, but I'm not sure how to retrieve the ID of the uploaded file in order to update metadata columns in the Document Library on the host. Thank you ...

Refreshing the three.js scene seamlessly within a single-page web application

I am currently working on a single page application that consists of multiple "slides," each implemented as a different hidden div, which becomes visible when it is the current slide. One of these slides features a canvas element and a ThreeJS scene. The ...

The variables do not align with the number of parameters specified in the prepared statement

As I work on developing an application, I encounter an issue with the login page where I need to verify if a user exists in the database. Although my code seems correct as I only check for the name, I am facing an error when implementing the prepared state ...

Synchronize two div elements with JavaScript

The demonstration features two parent divs, each containing a child div! The first parent div's child div is draggable and resizable using JQueryUI. There are events for both dragEnd and resizeEnd associated with this div. The goal is to synchronize ...

When hovering, apply style 1 to all elements with the same id, and style 2 to the hovered element

I'm working with some user-generated divs that I want to dynamically highlight when hovered over, while simultaneously blurring the other divs. My challenge is figuring out how to change the style of the hovered div separately from all the others. Th ...

Utilizing Directional and Spotlight Lighting with ThreeJS Helper Functions

I am currently utilizing a guide on implementing light in Threejs from Light in Threejs. I have successfully added some light to my scene. Now, I am attempting to add light to the character in my game but it is still not working. Even though I used the co ...

Authenticate the user by comparing the entered username and password with the database records. If they match, proceed to redirect the user to their profile page. Otherwise, log

Attempting to complete this assignment which involves a user entering their username and password. If the information matches what is stored in the database, the user should be redirected to their profile page where a personalized greeting message is displ ...

Implementing Autocomplete search with jQuery Chosen plugin - a step-by-step guide

CSS <select class="custom" id="company_hub" name="company_hub" style="width: 400px; display: none;"> <option>-Select Item-</option> </select> https://i.sstatic.net/x4YtN.png I attempted the following method but it was unsucces ...