Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
I want to compares the difference between two objs but ignore some key

I'm using Lodash to compare two objects returned from Postman but I want to ignore the dynamic values (page_view and deletion.update_time). How can I do this? I've tried passing in the property names into omit but it's not working... how can I resolve this issue? Thank you.

var obj1 = {
  name: "James",
  age: 17,
  page_view: "2",
  creation: "13-03-2016",
  deletion: {
    "article_id": 4469568,
    "update_time": 1226,
  }
}
var obj2 = {
  name: "James",
  age: 17,
  page_view: "62",
  creation: "13-03-2016",
  deletion: {
    "article_id": 4469568,
    "update_time": 12265,
  }
}

var result = _.isEqual(
  _.omit(obj1, ['page_view', 'update_time']),
  _.omit(obj2, ['page_view', 'update_time'])
);
if (!result) {
  pm.expect.fail("Pro and Sta are different")
}
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need to specify this on the sub-object:

var obj1={name:"James",age:17,page_view:"2",creation:"13-03-2016",deletion:{"article_id":4469568,"update_time":1226,}}
var obj2={name:"James",age:17,page_view:"62",creation:"13-03-2016",deletion:{"article_id":4469568,"update_time":12265,}}

const stripDynamicValues = o => {
  let toCompare = _.omit(_.cloneDeep(o), "page_view");
  // Here, you need to work explicitly on the sub-object
  toCompare.deletion = _.omit(toCompare.deletion, "update_time");
  return toCompare;
};

var result = _.isEqual(stripDynamicValues(obj1), stripDynamicValues(obj2));

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!