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

107
Vistas
How to create a function to add a new array to an object in javascript

I have data coming from the db and I want the user to be able to add a new array after adding the new changes. I want a function that can be used multiple times for different ajax calls.

My object array is var basinSub and the content of the object array is:

{BasinId: (array stuff), SubBasinId: (array stuff), SubBasinName: (array stuff)}

How can I create a for key in data function that I can add a new array to the basinSub object?

I was thinking something like this but it's not working:

function locationChangeData(value, desc) {
    for(var i in basinSub) {
        if(basinSub[i].value == value) {
            basinSub[i].desc = desc;
        }
    }
}

Then I would call the function in the ajax success function:

locationChangeData(basinSub, newSubBasinToAddSub);

Which newSubBasinToAddSub is the new array to add to basinSub.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This might do it

    //function to add new changes
    function targetChange(target, source) {
        Object.keys(source).forEach(function(key) {
            for(i=0;i<source.length;i++) {
                target[key][target[key].length++] = source[key][i];
            }
        });
    }
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