In my code, there is an array named 'plotData' which contains multiple 'rows' of data, each represented by a 4-element array. The array 'plotData' gets updated by a $.post() function further down in the script. The placeholders '...' indicate where some variables from the post request are utilized.
console.log("plotData (before update): ", plotData);
console.log("plotData length: ", plotData.length);
...
...
...
$.post(
"/csvgen",
{node_num: nodes.toString(), start_time: startTime.toString(), end_time: endTime.toString()},
function(data){
var nodeData = $.csv.toArrays(data);
nodeData.forEach(function(element){
plotData.push(element);
});
},
"text"
);
I expected the method calls for logging the array and its length to execute in sequence. However, upon checking the console output, I noticed that while the console log of the array shows 28 entries, the plotData.length output indicates only 14. As new elements are added to the array, it consistently appears to be 14 more than what is displayed as plotData.length.
The 'plotData' array is accessed elsewhere in the code but remains unaltered.
Why might this discrepancy occur?
Edit to add log
Can't plot empty data set
TypeError: Cannot read property 'length' of undefined(…)
plotData (before update): []
plotData length: 0
plotData (before update): [Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4]]
plotData length: 14
plotData (before update): [Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4], Array[4]
plotData length: 50
The initial error message occurs due to attempting to plot with an empty dataset.