JavaScript Object属性始终返回undefined [英] JavaScript Object property always returns undefined

查看:1247
本文介绍了JavaScript Object属性始终返回undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

告诉我这里缺少什么。我有跟随javascript对象。

Tell me what I am missing here. I have the follow javascript object.

[ { id: '16B0C2FC-A008-4E8A-849B-DB1251C8CABD',
    handle: '123',
    userId: 'ABC123'} ]

当我执行以下操作时

success: function (registration) {
                console.log(registration);
                console.log(registration.handle); 

控制台日志按上面的定义写出对象。但是,当我进行registration.handle时,我收到一条错误,上面写着未定义。如果注册是上述对象,为什么registration.handle不起作用?

Console log writes out the object as defined above. However when I do registration.handle I get an error saying "undefined." If registration is the above object why does registration.handle not work?

我错过了什么?

推荐答案

您有一个包含对象的数组。您尝试访问的属性是对象的成员,而不是数组。

You have an array containing an object. The properties you are trying to access are members of the object, not the array.

在访问其属性之前,必须先获取对象的引用。

You must first get a reference to the object before you access its properties.

registration[0].handle

这篇关于JavaScript Object属性始终返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆