Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

find difference in array of objects javascript

const arrayOne = [ 
  { value: "4a55eff3-1e0d-4a81-9105-3ddd7521d642", display: "Jamsheer" },
  { value: "644838b3-604d-4899-8b78-09e4799f586f", display: "Muhammed" },
  { value: "b6ee537a-375c-45bd-b9d4-4dd84a75041d", display: "Ravi" },
  { value: "e97339e1-939d-47ab-974c-1b68c9cfb536", display: "Ajmal" },
  { value: "a63a6f77-c637-454e-abf2-dfb9b543af6c", display: "Ryan" },
];
          
const arrayTwo = [
  { value: "4a55eff3-1e0d-4a81-9105-3ddd7521d642", display: "Jamsheer"},
  { value: "644838b3-604d-4899-8b78-09e4799f586f", display: "Muhammed"},
  { value: "b6ee537a-375c-45bd-b9d4-4dd84a75041d", display: "Ravi"},
  { value: "e97339e1-939d-47ab-974c-1b68c9cfb536", display: "Ajmal"},
];

const results = arrayOne.filter(({ value: id1 }) => !arrayTwo.some(({ value: id2 }) => id2 === id1));

console.log(results);
 Run code snippet
Comment

js difference between two arrays of objects

const a = [{ value:"0", display:"Jamsheer" }, { value:"1", display:"Muhammed" }, { value:"2", display:"Ravi" }, { value:"3", display:"Ajmal" }, { value:"4", display:"Ryan" }];
const b = [{ value:"0", display:"Jamsheer", $$hashKey:"008" }, { value:"1", display:"Muhammed", $$hashKey:"009" }, { value:"2", display:"Ravi", $$hashKey:"00A" }, { value:"3", display:"Ajmal", $$hashKey:"00B" }];

// A comparer used to determine if two entries are equal.
const isSameUser = (a, b) => a.value === b.value && a.display === b.display;

// Get items that only occur in the left array,
// using the compareFunction to determine equality.
const onlyInLeft = (left, right, compareFunction) => 
  left.filter(leftValue =>
    !right.some(rightValue => 
      compareFunction(leftValue, rightValue)));

const onlyInA = onlyInLeft(a, b, isSameUser);
const onlyInB = onlyInLeft(b, a, isSameUser);

const result = [...onlyInA, ...onlyInB];

console.log(result);
 Run code snippet
Comment

how to difference of arrey object

// src/App.js

import React from "react";
import Home from "./pages/Home";
import Singlepost from "./pages/SinglePost";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import "react-loader-spinner/dist/loader/css/react-spinner-loader.css";
import Navigation from "./components/Navigation";

function App() {
  return (
    <div className="App">
      <Router>
        <Navigation />
        <Switch>
          <Route path="/" exact component={() => <Home />} />
          <Route path="/:id" exact component={() => <Singlepost />} />
        </Switch>
      </Router>
    </div>
  );
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: set value input date javascript 
Javascript :: remove duplicates from array js lodash 
Javascript :: javascript stringify an object 
Javascript :: how to setItem and getItem in javascript in localStorage 
Javascript :: Read only directories in node 
Javascript :: exit program js 
Javascript :: popup alert in flutter 
Javascript :: can immigrants vote in uk 
Javascript :: how to use hover functionality using Jquery 
Javascript :: com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception unrecognized field 
Javascript :: redirect not found in react-router-dom 
Javascript :: javascript oncontextmenu 
Javascript :: jquery on enter click 
Javascript :: stopped typing jquery 
Javascript :: file system replace line js 
Javascript :: js upload json 
Javascript :: how to get data from user in javascript 
Javascript :: cypress scroll bottom 
Javascript :: javascript get child by name 
Javascript :: setlocalstorage 
Javascript :: angular formarray remove all 
Javascript :: reactjs firebase where map value 
Javascript :: how do i get month and date of javascript in 2 digit format 
Javascript :: javascript loop through object array 
Javascript :: add class tr datatable 
Javascript :: replace all spaces with dash in javascript 
Javascript :: references another schema in sequelize 
Javascript :: node crypto hmac sha256 
Javascript :: javascript folder exists 
Javascript :: capital first letter react 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =