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

142
Vistas
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 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