To create a subaddress, you need the wallet private keys. Assuming you have these, you can create them in javascript using [this package][1], as an example. You cannot do this only having the public key, you need the private keys. [1]: https://www.npmjs.com/package/subaddress