Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda