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

86
Views
Determine how many key values have changed in an object

I have two of the same objects to compare, with different data types as object props (array and object).

I want to know how many properties are different than the first one. See example below:

OriginalObject = {
 names : [],
 numbers : [],
 dates :{
  from: null,
  to : null,
 },
 other :{
  from: null,
  to : null,
 },
}

ModifiedObject = {
 names : ['Steven', 'Judy'],
 numbers : [1,5,7],
 dates :{
  from: 15152112512,
  to : null,
 },
 other :{
  from: null,
  to : null,
 },
}

Since names, numbers, and dates changed, desired output is: 3

I was thinking perhaps I could iterate over the object properties and use _.isEqual of lodash, but I would like to know if there is an easy and shorthanded version to do achieve this.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you want a solution using lodash, you could apply _.toPairs() on both of your objects. Then use _.differenceWith() to compare the obtained arrays and finally get the length of the comparison array :

OriginalObject = {
 names : [],
 numbers : [],
 dates :{
  from: null,
  to : null,
 },
 other :{
  from: null,
  to : null,
 },
}

ModifiedObject = {
 names : ['Steven', 'Judy'],
 numbers : [1,5,7],
 dates :{
  from: 15152112512,
  to : null,
 },
 other :{
  from: null,
  to : null,
 },
}

console.log(_.differenceWith(_.toPairs(OriginalObject), _.toPairs(ModifiedObject), _.isEqual).length);
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

about 4 years ago · Santiago Trujillo Report

0

I have used this as a solution.

 appliedFiltersCount (state) {
        let changedCount = 0
        Object.keys(state.filters).forEach((field) => {
          if (field in state.filters && field in getDefaultState().filters) {
            if (!isEqual(state.filters[field], getDefaultState().filters[field])) {
              changedCount++
            }
          }
        })
        return changedCount
 },
about 4 years ago · Santiago Trujillo 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!