this is the partial answer, on the underlying logic. I cannot help with java script. The critical part would be the base58decoding, but it seems there are solutions already: https://www.npmjs.com/package/base58check
Underlying logic:
the scriptpubkey contains the RipeMD160 Hash, surrounded by some codes:
a9 14 87. This is a P2SH address.
the meaning of the codes is:
a9 -> do a RipeMD160 on the top stack item
14 -> push hex 14 (decimal 20) bytes on stack
87 -> check if the top two stack elements are equal
From your address, you need four steps, to come to this goal:
1.) base58decode the address
2.) remove last 4 bytes (this is a checksum)
3.) remove the first two bytes (the network prefix
4.) surround the codes to it
effectivly the procedure is the revers of the standard "base58check encoding": which answers, how to come from a pubkey in hexformat to
an address:
0: have a Private ECDSA Key
1: derive the Public ECDSA Key
2: do a SHA-256 of 1
3: RIPEMD-160 Hash of 2
4: add address prefix 0x00 for P2PKH, 0x05 for P2SH
5. sha256
6. another sha256
7. take first four Bytes from step 6 as checksum
8. append checksum from step 7 to the result from step4
9. encode Base58
--> your bitcoin address !
help while testing: http://gobittest.appspot.com/Address
(hint: never put your production private keys into a webpage - you might/will loose the funds on it!)