I have two variables:
var cost = new Array();
var maxslot = new Array();
and I set the values like this:
<script>
cost = {"m2mp":"0.05"};
maxslot = {"m2mp":"1000"};
</script>
<script>
cost = {"samp":"0.04"};
maxslot = {"samp":"500"};
</script>
But samp replaces m2mp and if I call alert(cost["m2mp"]), it outputs undefined (if I don’t assign samp, I get the correct output). I tried replacing = with +=, but it did not help (samp and m2mp are both undefined then).
I couldn’t find any solution to “simulate” this:
cost["string"] = string;
Just do this:
However, the way you want your variables makes them
Objects, notArrays. So you’ll have to replace:With:
Or, you could just declare the variables and assign values to it in one line, in a “Object literal”: