I would like to link integer => something
in JavaScript without need of iterating over each element of array.
In PHP for example I can use arbitrary values without making array bigger.
Let's say my test JS code would be
let experiment = [];
experiment[1] = "hello";
experiment[1000] = "world";
console.log(experiment);
Given this example code, that array contains many empty elements, which implies it's not correct way to do this. I could in theory do array of objects where {int:1,val:'hello'}
but this would require me to iterate over said array to access one of elements, which is not what I need.
Is there better way to do this in JavaScript? If not, how bad is that method, like what's the amount of wasted memory for this?