Uncertain about how to phrase the question title or the correct way to ask for assistance with this issue.
The objective is to extract data from an external Json file consisting of approximately 700 entries. When iterating through these data items, such as data 1, data 2, data 3... and so forth, I aim to compare the current value with the previous one and take action based on whether it is greater, lesser, or equal.
Currently, my code looks like this
function myJson() {
$.getJSON('JsonData.json', function (response) {
setInterval(function () {
var TrialCount = response.length;
updateTrack(X_Data);
var counter = 0;
var Info = response[counter];
var X_Data = Info.X_Json;
X_Data = X_Data.toFixed(2); // rounds to 2 decimal places
document.getElementById("DisplayX").innerHTML = X_Data
counter++;
}, 500);
});
};
function updateTrack(X_Data) {
$('#X').html(X_Data);
if (current X_Data < previous value){
document.getElementById("X_Data_img").src = "first image";
}
else if (current X_Data > previous value) {
document.getElementById("X_Data_img").src = "second image";
}
else {
document.getElementById("X_Data_img").src = "third image";
}
};
How can I compare the current X_Data (current loop of Json data) with the previous X_data (previous loop of Json data)?
The format of the Json data I am working with
var X_Json= {
"data1" : "#",
"data2" : "#",
"data3" : "#",
..
},
{
"data1" : "#",
"data2" : "#",
"data3" : "#",
..
},
{
"data1" : "#",
"data2" : "#",
"data3" : "#",
..
},
{
"data1" : "#",
"data2" : "#",
"data3" : "#",
..
}