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

141
Visualizações
Array not resetting at end of loop

I have the code below that takes the subKeyValuesList and removes values from it as the loop iterates. This works however after each loop (it's one big array containing 4 arrays) I want the subKeyValuesList values to reset to the original value. Below I've tried to reset by applying some code to the last iteration of the loops but no joy. I think it may be a scope issue but have struggled to see where the issue is

 var subKeyValuesList = ['0009397b-563f-4dfc-8022-1516dbdffbda','1358d485-69e6-43bb-bc2f-ff25baa6a810']

   for (var fi = 0; fi < fields.length; fi++) {
       var subKeyValuesList2 = subKeyValuesList
       var fieldSplitTemp = fieldLong.replace(/[`~!@#$%^&*()_|+\=?;:'"<>\{\}\[\]\\\/]/gi, 'x')
       var fieldSplit = fieldSplitTemp.split("xix.")
       var fieldCount = fieldSplit.length
                                        
    var arrayPath = fieldSplit.splice(0, fieldCount - 1)

    for (let i = 0; i < eval(arrayPath[0]).length; i++) {
                
     for (let ii = 0; ii < eval(arrayPath[0] + "[i]." + arrayPath[1]).length; ii++) {
          var keyNames = Object.keys(eval(arrayPath[0] + "[i]." + arrayPath[1] + "[ii]"));
          var subKeyName = keyNames[0]
          var parent = eval(arrayPath[0] + "[i]." + arrayPath[1] + "[ii]." + subKeyName)
                            
         var index = subKeyValuesList2.indexOf(parent);
    
           if (index !== -1) {                                    
                                subKeyValuesList2.splice(index, 1)
                            }           
           if (ii == eval(arrayPath[0] + "[i]." + arrayPath[1]).length - 1) {
        //if last instance in loop do reset spliced list with original subKeyValuesList
                    subKeyValuesList2 = subKeyValuesList
                        }

                    }

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