Puts data into an array within a subscribe function

In my project, I have X and Y coordinate motion that allows the car to move. I want to be able to put this data into an array because I want to move a steering wheel to see where the car is going. However, for this, I need to be able to refer to the previous and next data. Can anyone help?

  tag5617.subscribe(function(message{
    let X = document.getElementById('posX');

    X.innerHTML = message.x.toFixed(2);

    let Y = document.getElementById('posY');

    Y.innerHTML = message.y.toFixed(2);

    myChart.data.datasets[0].data.push({x:message.x.toFixed(2), y:message.y.toFixed(2)});

    myChart.update();
        
    });