0

This is the result of my console.log(params):

currency_id: false
customer_id: 127505
"payment[account_name]": ""
"payment[iban]": ""
"payment[method]": "adyen_sepa"
store_id: "1"

I got this from ajax call and when I am doing this onSuccess :

 console.log(params.customer_id);  // I got the right value
 console.log(params.payment['method'])  // I am getting undefined
 var obj = "payment['method']";
 console.log(params.obj)  // still undefined 

How can I get teh value from payment[method] ? Thnx

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59

3 Answers3

1

How can I get teh value from payment[method] ? Thnx

Use bracket notation

var obj = "payment[method]";
console.log(params[obj])

Demo

var params = {
  currency_id: false,
  customer_id: 127505,
  "payment[account_name]": "",
  "payment[iban]": "",
  "payment[method]": "adyen_sepa",
  store_id: "1"
}

var obj = "payment[method]";
console.log(params[obj])  
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

It's a little confusing because the key name has brackets in it, so while you were close with your original code, try this instead:

params['payment[method]']

Using bracket notation you place the key name (all key names in JS objects are strings) in quotes.

Andy
  • 61,948
  • 13
  • 68
  • 95
0

Try like this,

var output = {
    currency_id: false,
    customer_id: 127505,
    "payment[account_name]": "",
    "payment[iban]": "",
    "payment[method]": "adyen_sepa",
    store_id: "1"
}
console.log(output['payment[method]']);