π:0
After you push a new element onto an array, the element before it is the 2nd to last element.
Unlike some other languages (e.g. Python) thereβs no shorthand syntax to index from the end of an array. So you have to calculate the index by subtracting from array.length
.
let deg = Math.atan2(message.x - arrX[arrX.length-2], message.y - arrY[arrY.length-2]) * 180 / Math.PI;