This seems quite simple, but I can’t figure it out.
In PHP, I could do something like this:
$number_children[reference_number - 1][$key] = value;
In Javascript, I need to do the same: set a value in an associative array, which is in a normal array.
I’ve tried this:
number_children[reference_number - 1][key] = $(this).val();
This didn’t seem to work. What’s a simple method of setting this value?
Thanks for any help in advance.
In Javascript arrays and “associative arrays” are different. In fact, Javascript people don’t use the term “associative arrays”, they call them “objects” (or “hashes”).
So, you can do this:
But this can have unexpected results when you try to iterate it, due to
lengthnot being set: