I am creating a JSON array exactly as follows (bar using mathrandom).
For example purposes:
var numbers = [];
var jsonString = "";
function EveryOneSec() {
numbers.push(Math.random());
jsonString = JSON.stringify({'numbers': numbers});
setTimeout(EveryOneSec, 1000);
}
When I create the JSON string it will obviously just keep getting bigger.
Is there a way that I can only have the 10 most recently added into the array?
Add the following code to the top of
EveryOneSecYou want to use
pushandshiftto ensure you always have the recent 10.