How to add possibly a for loop for this const to work properly?

Posted by NewOCLibraryReddit@reddit | learnprogramming | View on Reddit | 4 comments

I have been banging my head against a wall trying to get this code working properly. I am trying to add multiple outputs based on the number of the 'arrayOfAddresses' variable. And it just isn't working. Can you please provide some recommendations to how to approach the sutuation: const arrayofAddresses = ['address1', 'address2', 'address3', 'address4', 'address5'] const transaction = new bsv.Transaction() .from(utxo) .to(sendToAddress, amount) .addOutput( new bsv.Transaction.Output({ script: bsv.Script.buildSafeDataOut, satoshis: 0, }) ) .addOutput( new bsv.Transaction.Output({ script: bsv.Script.buildPublicKeyHashOut, satoshis: userServiceFeeTotal, }) ) .addOutput( new bsv.Transaction.Output({ script: bsv.Script.buildPublicKeyHashOut('arrayofAddresses'), satoshis: userAmount, }) ) .fee(us) .change(u) .sign(userP);