• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

JavaScript: Use anything for object property name including spaces and quotes

I want to be able to use ANYTHING for a JavaScript property name, including unicode characters, spaces and quotes.

For example:
ß¿¿
¿¿
Hello World
test "123"

How can I do this?

var doc=new Object();

doc.Hello=1;
doc.World=2;
doc.¿ß¿ss¿¿=3;
doc.¿¿=4;
doc.Hello World=5;
doc.test "123"=6;

alert( JSON.stringify(doc) );

Open in new window

0
hankknight
Asked:
hankknight
  • 2
1 Solution
 
COBOLdinosaurCommented:
Not going to happen.  Some characters might work, but not all.  space not a chance. quote character no chance.  Any character that is an operator... not going to happen.

Dead end, you will need to go back to the drawing board, because this is not going to happen.

Cd&
0
 
hankknightAuthor Commented:
Where can I find documentation about specifically what characters are allowed or not allowed?
0
 
COBOLdinosaurCommented:
The standards specification is here;

http://www.ecma-international.org/publications/standards/Ecma-262.htm


A description of character usage is here:
http://mathiasbynens.be/notes/javascript-identifiers

Cd&
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now