With web3js, how do you figure out that there was 40000 tokens transfer from the transaction's hash?
There's a very good blog post on Medium using the exact method you're interested in.
(Stealing from the post):
input
data from web3.eth.getTransaction()
This will return the hex data for the function and parameters sent in the transaction. It will look something like 0xa9059cbb0000000000000000000000007adee867ea91533879d083dd47ea81f0eee3a37e000000000000000000000000000000000000000000000000d02ab486cedbffff
.web3.utils
to convert to decimal.