Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing attribute name containing slash in javascript object

Hi I'm trying to access an js object property which has an slash "/" in its name.

The object its somthing like:

{
   my/key : "my value"
   // more stuff here...
}

I try the following construction:

myObject["my/key"]

If I try to it in Chrome DevTools it works correctly but when I execute my code i get a beautiful undefined on browser console (using console.log())

has anybody any idea of what's happening? :S

like image 263
SergiGP Avatar asked Aug 22 '13 12:08

SergiGP


1 Answers

When you enclose the prop name into quotes, it works also in the code:

var obj = {
    'my/key' : 'my value'
};

You can check this at jsFiddle.

like image 171
Teemu Avatar answered Sep 26 '22 00:09

Teemu