Tengo un intervalo de tiempo ejecutandoce que quiero coincidir con el tiempo transcurrido con un objeto, pero el tiempo trancurrido no coincide con el tiempo del objeto. Estoy pensando la mejor forma de hacerlo como se les ocurriria a ustedes realizarlo
var testJSON = {
"9352": {
"data": {
"x": 220,
"y": 188
},
"time": 9352
},
"9452": {
"data": {
"x": 221,
"y": 186
},
"time": 9452
},
"9954": {
"data": {
"x": 221,
"y": 184
},
"time": 9954
},
"10054": {
"data": {
"x": 221,
"y": 184
},
"time": 10054
},
"10154": {
"data": {
"x": 221,
"y": 183
},
"time": 10154
},
"10554": {
"data": {
"x": 220,
"y": 183
},
"time": 10554
},
"10654": {
"data": {
"x": 218,
"y": 182
},
"time": 10654
},
"10754": {
"data": {
"x": 217,
"y": 181
},
"time": 10754
}
};
function handleActivity() {
var timeElapsed, activity, last;
var startingTime = Date.now();
if (testJSON) {
activity = testJSON;
last = Object.keys(activity)[Object.keys(activity).length - 1];
console.log('total: ' + Object.keys(activity).length);
var timer = setInterval(function() {
timeElapsed = parseInt(((Date.now() - startingTime) / 1000).toFixed(3).replace(/\./g, ''));
if (true) {
console.log(activity[timeElapsed]);
}
if (last <= timeElapsed) {
clearInterval(timer);
}
}, 100);
}
}
Se ejecutara por 10s cuando termina deberia mostrar los 8 objetos encontrados pero como el intervalo se saltea ciertos numeros no mostrara nada o solo alguno de los 8.
Ya estoy cansado no puedo pensar mas