We can solve this using inclusion and exclusion principle
Let $A = \{0,1,2,3,4\}$ and $B = \{0,1,2,3\}$
The total number of functions from $A$ to $B$ is $4^5 = 1024$
Total number of functions which miss one element in $B=$ $^{4}\text {C}_1$ $3^5 = 972$
Since we have to choose from $3$ elements from set $B$ and the number of ways in which we can exclude one element from $B$ is $^{4}\text {C}_1$
Similarly, Total number of functions which miss $2$ elements in $B=$$^{4}\text {C}_2$ $ 2^5 = 192$
And , Total number of functions which miss $3$ elements in $B=$$^{4}\text {C}_3$ $ 1^5 = 4$
Thus , Total number of surjective functions = Total functions$−$Functions missing at least one element$+$Functions missing at least two elements$−$Functions missing at least three elements.
$= 1024-972+192-4$
Total number of surjective functions $=240$