How can i use Unicode string key In Javascript Object?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 17:06:28

问题


I want to use unicode string in Object as key, something as:

var t = {"姓名": "naitong"};

it's ok , t["姓名"] return "naitong"

but

Object.keys({"姓名": "naitong"})

I got " ", a blank string

Anyone knowes why?

Editting:

I install firebug and try it in the console, it works. Acctually i use mozrepl, so that i can editing and run javascript in emacs. So This have something to do with mozrepl

I have confirm that mozrepl support only "7bit safe ASCII", to tranform unicode ,i have to json-encode it in emacs, as:

alert(Object.keys(JSON.parse("{\"\\u59d3\\u540d\":\"naitong\"}")))

This is my first question asked on stackoverflow, and i got quick resp. Thank you all.


回答1:


Works fine for me in the firebug console:

>>> Object.keys({"姓名": "naitong"})
["姓名"]

Maybe you are trying to display it on a page that uses a different charset which does not contain those symbols.



来源:https://stackoverflow.com/questions/9681002/how-can-i-use-unicode-string-key-in-javascript-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!