8

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.

Naitong Xiao
  • 81
  • 2
  • 4
  • One one browser? On all browsers? Which? – hippietrail Mar 13 '12 at 09:15
  • What platform? If Windows, that'll be your problem: the C stdio interface that's (probably) used by emacs's connection to mozrepl is limited to the locale's code page, which on Windows is unfortunately never a UTF, so you can't get arbitrary Unicode down it. – bobince Mar 13 '12 at 21:12

1 Answers1

3

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.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Chrome console also confirms success `> Object.keys({"姓名": "naitong"})` -> `["姓名"]` – Hubro Mar 13 '12 at 09:09