Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!