Are there ways for us to push the data from the console.log into an array and then perform calculation?

i was wondering if it is possible for us to create a function that stores the data from the console.log for every 1 minute into the array and then perform some calculations (sum,average,etc).
So far i have done is putting the 1 minute values that is shown in the console.log to the array and what i want to now is that it automatically reads the data from the console.log
the following code are the sum function and the binance api.

var nums = [1702.71 ,1702.66, 1702.66, 1702.66, 1702.66, 1702.66, 1703.03, 1703.03, 1703.03, 1703.09, 1703.08, 1703.44, 1703.44, 1703.45, 
1703.72, 1703.72, 1703.49, 1703.54, 1703.28, 1703.84, 1702.85, 1702.75, 1702.65, 1702.65, 1702.65, 1702.65, 1702.35,1702.34 ];

var totalSum = 0;
for(var i = 0; i < nums.length; i++) {
    totalSum += nums[i];
}
var avg = totalSum / nums.length;
avg = (Math.round(avg * 100)/100).toFixed(2);
document.getElementById("avgStock").innerHTML = avg;

let ws = new WebSocket('wss://stream.binance.com:9443/ws/etheur@trade');
let stockPrice = document.getElementById('pricestock');
let lastPrice = null;
var price;
ws.onmessage = (event) => {
let StockObject = JSON.parse(event.data);
let price = parseFloat(StockObject.p).toFixed(2);
stockPrice.innerText = price;
// Ternary Operation 
stockPrice.style.color = !lastPrice || lastPrice === price ? 'black' : price > lastPrice ? 'green' : 'red';
lastPrice = price;
console.log(price);

Would love to ask for some help and tips for me to achieve what i want. Thanks for your help!