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

103
Vistas
Need to return more than 1 value from a recursive fuction in javascript. Needto return the data in the format mentioned

Code for reference. There is an issue for the value returned as removeKey, it is always getting a null value.

const clearEmpties = (obj: IParms) => {
        var removeKey: string[] = []
        for (var key in obj) {
            if (!obj[key] || typeof obj[key] !== "object") {
                continue
            }
            clearEmpties(obj[key]);
            if (Object.keys(obj[key]).length === 0) {
                removeKey.push(key)
                console.log("k", key, obj[key]);
                delete obj[key];
            }
        }
        return {obj , removeKey};
    }

Input for the code snippet is :

{"a" :{
"m": {
"m1": "cmp",
"m2": "M2M",
"m3": "2"
}
"p":{}
}
}

Output should be : 2 values , return an object by removing all empty objects & list the removed path.

{"a" :{
    "m": {
    "m1": "cmp",
    "m2": "M2M",
    "m3": "2"
    }   
    }
 }

& removeKey = a.p

about 4 years ago · Juan Pablo Isaza
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