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,437
  • 5
  • 31
  • 57

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
  • 64,240
  • 8
  • 67
  • 88
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
  • 53,323
  • 11
  • 64
  • 89
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]']);