const x = msg.payload.slice(-30); should return the last 30 indices.
const x = msg.payload.slice(-30);