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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.