If I do the following,
var array = [];
array['foo'] = [];
console.log(array.length) // => 0
the console.log prints 0 length.
Is there a way to push key-value to arrays in javascript? Is it a bad idea in general? Do I need to keep the length updated myself?
There is the option to use bracket notation as recommended here (SO - JavaScript Array Push key value).
But later in the code I want to push to the object/array and SO recommends to use arrays again (SO - Appending to an object).
So I'm not quite sure which datastructure to use. For my task I guess I need key-values. Its an async-task and I can't rely on the order in an unnamed array. But from what I read so far, it seems kind of a hack to append to objects, too.