gpt4 book ai didi

javascript - 为什么我的 JS 对象最终有 "undefined"值?

转载 作者:行者123 更新时间:2023-11-30 18:16:58 25 4
gpt4 key购买 nike

var testRuleInput = {
"ruleName" : "renderDataVerificationFields",
"dependencies" : [
{
"fieldName" : "mailingStreetAddress",
"resource" : "verificationResults",
"attribute" : "verifyStreetAddress"
}
]
};

但是,当我稍后调用 console.log(testRuleInput.dependencies.attribute) 时;我得到 undefined。糊涂了!

最佳答案

dependencies 是一个对象数组。

更新您的代码:

console.log(testRuleInput.dependencies[0].attribute)

或者删除数组语法:

"dependencies": {
"fieldName": "mailingStreetAddress",
"resource": "verificationResults",
"attribute": "verifyStreetAddress"
}

关于javascript - 为什么我的 JS 对象最终有 "undefined"值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13017940/

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