简体   繁体   English

无法访问 JS object 的元素

[英]Can't access element of JS object

This may be the dumbest question in the world, but somehow I'm not being able to access the element Customer Support in this object, it returns undefined这可能是世界上最愚蠢的问题,但不知何故我无法访问此 object 中的元素Customer Support ,它返回undefined

This is my object:这是我的 object:

obj = {
    "channel_ids": {
        "IT": 258403,
        "HR": 258404,
        "Design": 258409,
        "Marketing": 258398,
        "Sales": 258413,
        "Writing": 258414,
        "️Customer Support": 258399,
        "Education": 260535,
        "Finance": 258406,
        "Executive": 258407,
        "Admin Assistant": 260554,
        "Social Media": 258405,
        "Legal": 258415
    }
}

When I do, for example, obj.channel_ids['Social Media'], it works, obviously例如,当我执行 obj.channel_ids['Social Media'] 时,它显然有效在此处输入图像描述

But when I do obj.channel_ids['Customer Support'], it doesn't, and I have no idea why但是当我做 obj.channel_ids['Customer Support'] 时,它没有,我不知道为什么在此处输入图像描述

What am I missing here?我在这里想念什么?

You have a hidden character (hex fe0f ) in your object definition above, right after the quotation mark.您在上面的 object定义中有一个隐藏字符(十六进制fe0f ),就在引号之后。 When I copy your object definition I can't access Customer Support, but when I erase and re-type that property manually I can.当我复制您的 object 定义时,我无法访问客户支持,但是当我手动擦除并重新键入该属性时,我可以。

Compared your reference to the object that worked versus manually typing it out in sublime and found a hidden character pre-pended to the "Customer Support" variable.将您对 object 的引用与在 sublime 中手动输入它进行比较,发现“客户支持”变量前面有一个隐藏字符。

Comparison比较

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM