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?