What is the best way to evaluate the rows of two specific elements?

My validation process involves comparing individual rows in the clientDocument with the corresponding rows in the serverDocument, instead of comparing the entire documents at once. Currently, I am using the following code snippet for comparison:


JSON.stringify(clientDocument.scheduledLines) != JSON.stringify(serverDocument.scheduledLines)

Here are some data samples for better understanding:

// clientDocument: scheduledLines
[
    {
      _id: '6604',
      resourceId: '5b482',
      workOrderId: 'muoj'
    },
    {
     _id: '9431',
      resourceId: '9w214',
      workOrderId: 'wocs'
    }
]

// serverDocument: scheduledLines
[
    {
      _id: '6604',
      resourceId: '5b482',
      workOrderId: 'muoj'
    },
    {
     _id: '9431',
      resourceId: '9w214',
      workOrderId: 'eiws'
    }
]

Answer №1

Below is a code snippet that results in an array with 2 different types:

  1. Rows in the first array that do not have the _id present in the second array.
  2. Rows in the first array that have the _id present in the second array but with different objects.
let t1 = [
    {
      _id: '6604',
      resourceId: '5b482',
      workOrderId: 'muoj',
    },
    {
     _id: '9431',
      resourceId: '9w214',
      workOrderId: 'wocs', 
    }
  ]

let t2 = [
    {
      _id: '6604',
      resourceId: '5b482',
      workOrderId: 'muoj',
    },
    {
     _id: '9431',
      resourceId: '9w214',
      workOrderId: 'eiws', 
    }
  ]

let result = t1.filter((itm1)=>{
    let _id1 = itm1._id;
    return !t2.some((itm2)=>{
        let _id2 = itm2._id;
        return JSON.stringify(itm1) === JSON.stringify(itm2)
    })
})

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

Facilitate parent directory navigation

Hello everyone! I am currently developing an express application. At the top of my express file, I added this line to serve all static files from my working directory: app.use(express.static(__dirname)); Now, I am trying to send a file that is located in ...

What is the best way to showcase two div elements side by side within my carousel

/* Implementing slideshow functionality */ var currentIndex = 0; displaySlides(); function displaySlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i ...

The Vuetify data-table header array is having trouble accepting empty child associations

My Vuetify data-table relies on a localAuthority prop from a rails backend. Everything runs smoothly until an empty child association (nested attribute) is passed, specifically 'county': <script> import axios from "axios"; exp ...

unable to log out firebase user

Currently, I am attempting to sign out the user who is already signed in within my Angular app. Here is my client service code: export class AuthClientService { public register(email: string, password: string): Observable<Object> { retu ...

How can I use Ajax to show only one div on the entire page while keeping the CSS and other header content intact

One of my clients is looking to integrate a merch shop into their website. The existing merch page is not visually appealing and doesn't match the aesthetic of the client's site. I am considering using AJAX GET to fetch the content of the merch p ...

What is the process for binding an absolute path instead of a relative path in a script that includes Node and Perl calls?

In my script, there is a function with the following code: def tokenize(latex,kind='normalize'): output_file = './out.lst' input_file = './input_file.lst' cmd = "perl -pe 's|hskip(.*?)(cm\\|in& ...

The JSX snippet accurately displays the expected value on some pages, but displays an incorrect value on other pages

{_id === friendId || <IconButton onClick={() => patchFriend() } sx={{ backgroundColor: primaryLight, p: "0.6rem" }} > {isFriend ? ( <PersonRemoveOutlined sx={{ color: primaryDark }} /> ...

Tips for effectively dividing a component's code into smaller sub-components

Within my component MyComp, there exists an extensive code that I wish to divide into 3 separate components. In envisioning the structure of MyComp, I am seeking general advice and a brief example in response: import React, { Component, Fragment } from & ...

The search for 'partition' in 'rxjs' did not yield any results

Recently, I attempted to incorporate ng-http-loader into my Angular project. After successfully installing the ng-http-loader package, I encountered an error during compilation. The specific error message displayed was: export 'partition' was ...

Discover the size of an image using JavaScript by accessing innerHTML

I'm currently working on a unique AJAX function that retrieves image URLs without using node append for insertion. Instead, I opted to utilize innerHTML, but this has posed challenges in accurately obtaining the file dimensions. My current approach i ...

How can I utilize the Json data retrieved through the findById method in my code?

My current project involves creating an API that retrieves data from Patients (id and name), Physicians (id and name), and Appointments (id, phyId, patId, app_date) in order to display the patients scheduled to see a specific physician. To achieve this, I ...

What steps should I take to update the state of this navbar?

Trying to understand why the prop I want to pass won't work with the toggle function: function custToggle({e}){ e.custOrFalse= !e.custOrFalse; var custButton='cust page' if ( e.custOrFalse==true ) { custButton='cust lo ...

Guide to making a dropdown menu that pulls information from a text box and displays the location within the text

I'm currently working on a unique dropdown feature that functions like a regular text field, displaying the text position. To achieve this, I've constructed a hidden dropdown menu positioned beneath the text field. My goal is to develop a jQuery ...

What causes an "Internal Server Error" when attempting to use data for a database request with AJAX GET/POST in Laravel?

There's a unique issue that I'm struggling to resolve... Every time I drag and drop an event into the calendar, an Ajax Post Request is sent to my controller. The controller then inserts some data into the database with the event name received v ...

Clearing AsyncStorage in React Native

It has come to my attention that I am spending a significant amount of time debugging redux actions in react-native that are being persisted to AsyncStorage using redux-persist. There are instances where I wish I could simply clear AsyncStorage in order to ...

Tips for transmitting and utilizing information in ejs or jade with a node js server

I'm currently working on a project where I need to send data stored in localstorage from an ajax call to a node js server. The goal is to use the retrieved data to customize an html page using ejs or jade templates. I've attempted to send my data ...

Guide on adjusting PHP variable values and updating functions with ajax requests

One of my functions determines dates based on a variable For example: $modification = "+1 Week" function updateCalendar($change){ $month = array("January","February","March","April","May","June","July","August","September","October","November","Dece ...

The request to http://localhost:3000/cartdata has encountered an internal server error (500) in the isAxiosError.js file at line

Error Image I'm currently working on developing a shopping cart feature, and I've encountered an issue when transferring data from the client side to the server side. Despite the cart data being successfully updated in the session, an internal se ...

The values in my JavaScript don't correspond to the values in my CSS

Is it possible to retrieve the display value (display:none; or display:block;) of a div with the ID "navmenu" using JavaScript? I have encountered an issue where I can successfully read the style values when they are set within the same HTML file, but not ...

Tips for passing registration form data, uploading images, and implementing validation via Ajax in CodeIgniter

As I work on creating a comprehensive registration form with all necessary data and input tags, I encountered an issue while attempting to pass the image upload value to the next page through AJAX. I need assistance in resolving this problem specifically r ...