Is there another (more beautiful) way to initialize this Javascript array?
var counter = [];
counter["A"] = 0;
counter["B"] = 0;
counter["C"] = 0;
counter["D"] = 0;
counter["E"] = 0;
counter["F"] = 0;
counter["G"] = 0;
A. That doesn’t work, or at least not the way you’d hope it to. You initialized an array when what you’re most likely looking for is a hash.
counterwill still return[]and have a length of0unless you change the first line tocounter = {};. The properties will exist, but it’s a confusing use of[]to store key-value pairs.B: