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

100
Vistas
Variable getting empty

Object variable getting empty once its data is assigned to a new variable and try to remove all the records from that new variable.

In the below variable DraftData, I have assigned api response which is an object. Then passed that DraftData to a method function1() as a parameter as mentioned below.

$.ajax({
    url: '../Layer/DraftList',
    type: 'GET',
    cache: true,
    dataType: "json",
    success: function (response) {
        DraftData = response;         
        function1(DraftData);
    } 
});

function function1(List) {    
    var ListTemp = List;   
    for (var i = MinFieldPriority; i <= MaxFieldPriority; i += 10) {
        const DataTemp = ListTemp.filter(x => x.FIELD_PRIORITY == i);
        //...
        //...
        ListTemp.splice(ListTemp.findIndex(a => a.FIELD_SK === DataTemp[0].FIELD_SK), 1)
    }
}

In the above method, after using ListTemp.splice(ListTemp.findIndex(a => a.FIELD_SK === DataTemp[0].FIELD_SK), 1) to delete records one by one after its use, it also deletes records from the DraftData as well which is used in the ajax success call. Actually I want original content in the DraftData variable. That is why I assigned it to a temporary variable ListTemp. But after executing the method function1(), data in the DraftData variable also becomes empty.

Any idea why it is happening?

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