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

88
Vistas
Pushing value to array that is the value of an object

I have the following structure:

let mappings = {
    "1002": ["1000", "1003"],
    "2000": ["2001", "2002"]
}

and I want to add this piece of data

const issueTypes = ["4000"]

to each of the arrays of the object keys ending with this

mappings = {
    "1002": ["1000", "1003", "4000"],
    "2000": ["2001", "2002", "4000"]
}

This is what I have so far:

mappings = Object.keys(mappings).reduce((prev, curr, index) => {
            console.log("prevous", prev)
            console.log("curret", curr)
        return ({
            ...prev, [curr]: //unsure of this part which is kind of crucial
        })}, mappings)

Any help would be really appreciated

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Why not just iterate over the values of the object, and push?

const mappings = {
    "1002": ["1000", "1003"],
    "2000": ["2001", "2002"]
}
const issueTypes = ["4000"]
for (const arr of Object.values(mappings)) {
  arr.push(...issueTypes);
}
console.log(mappings);

If it must be done immutably, map the entries of the object to a new array of entries, while spreading the new issueTypes into the value.

const mappings = {
    "1002": ["1000", "1003"],
    "2000": ["2001", "2002"]
}
const issueTypes = ["4000"]
const newMappings = Object.fromEntries(
  Object.entries(mappings).map(
    ([key, arr]) => [key, [...arr, ...issueTypes]]
  )
);
console.log(newMappings);

about 4 years ago · Juan Pablo Isaza Denunciar

0

The procedure is quite simple. What you need to do is this —

  • Iterate over each value of the mappings object.
  • Push the new value

Refer to the following code and adapt —

let mappings = {
    "1002": ["1000", "1003"],
    "2000": ["2001", "2002"]
}

const issueTypes = ["4000"]


for (const item in mappings) {
    mappings[item].push(issueTypes[0])
}

Hope this helps! :)

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