Currently, I have a web application that conducts basic analytics on user-imported data. Users can map columns and view property information on a map, as well as various statistics related to the properties.
We are in the process of implementing a new feature that relies on the specific mapped column. As I review the feature, I am encountering difficulty understanding the output and identifying any potential issues. Below is the relevant function where I provide a list of objects and eliminate the data associated with the unified field through mapping. For instance, 'Address' might be the guess and 'Street Address' could be the mapping.field from the CSV file.
deleteMapping(field: string, data?: Array<any>, render?: boolean)
{
if (!field || typeof field !== 'string')
throw { message: "delete mapping expects a string parameter"}
var mapping = this.mapping[field];
if (!mapping)
return;
this.mapping[field] = null;
this.inverseMapping[mapping.guess] = null;
if (Array.isArray(data))
{
console.log(mapping.guess);
console.log(data);
for (var i = 0; i < data.length; i++)
{
console.log(data[i][mapping.guess]);
data[i][mapping.guess] = null;
console.log(data[i][mapping.guess]);
}
console.log(data);
try
{
$("body").trigger("analytics:unbind",{ field: mapping.field, unified: mapping.guess, render: render === undefined ? true : render});
}
catch (e)
{
console.error(e);
}
}
}
The issue I am facing lies in the confusion surrounding the console logs.
- mapping.guess = 'Address' as expected
- data = My Initial Array as expected
- First data[i][mapping.guess] = the Address of the individual property as expected
- Second data[i][mapping.guess] = null as expected
- data = My Initial Array UNCHANGED
I am puzzled as to why the value of the array item remains unchanged after setting it to null. Any suggestions? Additionally, I find it perplexing how data[i][mapping.guess] returns correctly within the loop. I am bewildered as to why the value does not update to null in the array following the loop.
Edit: ...I believe I have identified the issue. It appears that the console.log operation may be somewhat asynchronous. The address seems to reconstruct itself during the subsequent 'unbind' event, resulting in a different output when printed out due to other data interactions. I had not considered that console.log might delay its outputs.