0

Is it possible to store an Object into an Object..I have tried to this in my code with entry:entry but no success.

I have no problem with Object[String, String] but Object[Object, String] is not working for me.

$.each(data.scheduleEntries, function(index, entry){
  arr[{entry:entry}] = entry.startDate;
})
kidwon
  • 4,448
  • 5
  • 28
  • 45
Timvdb92
  • 63
  • 9
  • 1
    `arr[{entry:entry}] = entry.startDate;` Uh? Why are you using an object literal as an index? – Frédéric Hamidi Feb 19 '15 at 11:10
  • An object always requires a `key:str -> value:any` syntax, you cant just do `{key: object, string}` Also, try to use english for all code. I know `teller` is dutch for counter but it's best practise to keep using english everywhere ;) – somethinghere Feb 19 '15 at 11:10
  • 1
    See https://stackoverflow.com/questions/6066846/keys-in-javascript-objects-can-only-be-strings . Tl;dr: keys in javascript objects can be strings and strings only. – bardzusny Feb 19 '15 at 11:10

1 Answers1

0

No, it is not possible to use objects as keys in objects. Property names always are strings. You can use objects as property values of course.

In your case, using arr[entry] directly should work; if you really need objects as keys you will be able to use Map objects with ES6 (there also exist less efficient shims).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375