JoJo
JoJo

Reputation: 4933

How do I add parameters to an object using variables?

I have this snippet of code:

var ShopLogicOptions = {};
ShopLogicOptions.params = {orderId: "'" + JS_OrderNo + "'", cartItems:[JS_arrCartItems], subTotal: "'" + JS_SubTotal + "'",...

How do I correctly put variable JS_OrderNo in the position it is at?

The other server is receiving this: "'9134832'",

And it should be this: '9134832',

EDIT: When I document.write JS_OrderNO it looks like this 9134832, so I have to add the single quotes.

Upvotes: 0

Views: 63

Answers (2)

gdoron
gdoron

Reputation: 150293

remove the single quote

{orderId: "" + JS_OrderNo  

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318638

Remove the quotes.

var ShopLogicOptions = {};
ShopLogicOptions.params = {
    orderId: JS_OrderNo,
    cartItems: [JS_arrCartItems],
    subTotal: JS_SubTotal,
    ...
};

If you really need a string instead of a number, use this:

orderId: String(JS_OrderNo),

Upvotes: 3

Related Questions