Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda