0

Im trying to create an associative array with objects, the key should always be a string (but they are always numbers). This is how i store them (recording user clicks):

App.Recording[currentTime.toString()] = {sound: buttonName.toLowerCase() };

When trying to do this:

var save = {};

save.recording = App.Recording;
console.log(JSON.stringify(save));

I get this:

{"recording":[null, null,{"sound":"e"},null,null,null,.......,null,null,null,null,{"sound":"e"},....,null, null...]}

So, the toString() doesnt work on currentTime.toString(), which make my array store currentTime as numbers instead...

How can I save the objects and have an associative array?

flavian
  • 28,161
  • 11
  • 65
  • 105
tobbe
  • 1,737
  • 6
  • 23
  • 40

1 Answers1

1

Have a look HERE first. There are no associative arrays in JS. Instead of an array, you should use an object with a for in loop.

Community
  • 1
  • 1
flavian
  • 28,161
  • 11
  • 65
  • 105