check if two object list have the same property

140
March 10, 2018, at 05:59 AM

I have two objects lists which they have different fields in them.I want to check if two fields dont have same value in them in javascript. my example is list one

0:Client_Issue_Reference__c:null
  End__c:"2018-03-06T23:00:00.000Z"
  Id:"a0Q2F000000oRyBUAU"
  Resource_Full_Name__c:"test user"
  Start__c:"2018-03-06T15:00:00.000Z"

and my second list is

0:Id:"0050W000006r0xnQAA"
  IsActive:true
  Name:"test user"

I wanna see if Resource_Full_Name__c != Name currently I have

for (var i = 0; i < listOne.length; i++) {
  for (var j = 0; j < listTwo.length; j++) {
     if (listOne[i].Name != listTwo[j].Resource_Full_Name__c) {
          buildingObjectAllUser = {}
          sobjectType: "testObject";
          buildingObjectAllUser.Id = listOne[i].Id;
          buildingObjectAllUser.Start__c = "2018-03-06T23:00:00.000Z";
          buildingObjectAllUser.End__c = "2018-03-06T23:00:00.000Z";
          buildingObjectAllUser.Name = "No Hours";
          buildingObjectAllUser.Resource_Full_Name__c = listOne[i].Name;
          listThree.push(buildingObjectAllUser);
        }
      }
    }

the problem with this one is taking to much time, its really slow

Answer 1

this should be faster

let list1 = [{Client_Issue_Reference__c:null,
  End__c:"2018-03-06T23:00:00.000Z",
  Id:"a0Q2F000000oRyBUAU",
  Resource_Full_Name__c:"test user",
  Start__c:"2018-03-06T15:00:00.000Z"}]
let list2 = [{Id:"0050W000006r0xnQAA",
  IsActive:true,
  Name:"test user"}]

list1.map(obj => {
  let checker = list2.find(obj2 => obj2.Name === obj.Resource_Full_Name__c)
  if (!checker) {
    let buildingObjectAllUser = {}
    sobjectType: "testObject"
    buildingObjectAllUser.Id = listOne[i].Id
    buildingObjectAllUser.Start__c = "2018-03-06T23:00:00.000Z"
    buildingObjectAllUser.End__c = "2018-03-06T23:00:00.000Z"
    buildingObjectAllUser.Name = "No Hours"
    buildingObjectAllUser.Resource_Full_Name__c = listOne[i].Name
    listThree.push(buildingObjectAllUser)
    return buildingObjectAllUser
  }
})
Rent Charter Buses Company
READ ALSO
jQuery to affect Vue component&#39;s named slot

jQuery to affect Vue component's named slot

How can I make the JavaScript (specifically jQuery) in a parent propagate down into the named slot of a child component that is used in the parent component?

145
custom jQuery not working with featherlight.js

custom jQuery not working with featherlight.js

I seem to be having an issue executing jquery within a window that is displayed via featherlightjs

203
Issues with jQuery&#39;s relative animations

Issues with jQuery's relative animations

I'm having an issue with a website I've been working onIt works perfectly up until it gets to

147
jQuery Extension Scope Doesn&#39;t Have Access to Element

jQuery Extension Scope Doesn't Have Access to Element

Why isn't the $widget variable accessible from the value function?

194