Ok, so let's step through your loop, replacing instances of the variable bla
with the string value of 'blabla'
:
if (!myarray['blabla']) {
myarray['blabla'] = [];
}
Arrays in javascript are index by integer values. What your code here is doing is adding an expando property to the array instance named blabla
. That is:
myarray.blabla = [];
now reconsider your increment statement:
myarray['blabla'][bl] += i;
or, with the expando properties:
myarray.blabla.bl // remember that "myarray.blabla" is set to the empty array above
What this is trying to do is access the property named bl
on the empty array. That's why you're getting undefined
here.
Anyway, as a best practice, you might want to avoid using arrays in javascript like hashtables, since problems like this are bound to crop up after enough time.