gpt4 book ai didi

javascript - 访问JavaScript中的对象问题

转载 作者:行者123 更新时间:2023-12-03 02:40:41 25 4
gpt4 key购买 nike

这是我的console.log(params)的结果:

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

我从ajax调用中得到这个,当我这样做时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

如何从 payment[method] 获取值?谢谢

最佳答案

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

使用括号表示法

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

演示

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])

关于javascript - 访问JavaScript中的对象问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48337411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com