1

I request some data from my database which returns me an Value which is the Type of an int.

var id = databaseReturn["id"]; //-> int 2

Now when I try to make an Array with and key of that value it doesnt work because it is an int, but even after converting it to a String it doesnt work.

id = String(id); //Should be -> String "2"
array[id] = []; //array[2] = [] but should be array["2"] = []

How do I fix that ?

1 Answer 1

2

Don't use arrays if you're not going to use int indexers. Just use Object for it:

var obj = {};
obj[id] = //whatever

When you use objects, it will convert the key automatically to string too.

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.