I have categorized data with unique IDs spread across different collections.
I am in need of quick and direct access to this data based on the ID, as well as efficient looping over the entire dataset.
var dataSetA = {
34523: { foo: 7, bar: 123},
6435: { foo: 2, bar: 163},
3123: { foo: 3, bar: 223},
...
};
var dataSetB = {
34523: { baz: 1},
6435: { baz: 4},
3123: { baz: 6},
...
};
Retrieving specific parts of data by ID is fast but iterating through all data entries can be slow.
var dataSetA = [
{ id: 34523, foo: 7, bar: 123},
{ id: 6435, foo: 2, bar: 163},
{ id: 3123, foo: 3, bar: 223},
...
];
var dataSetB = [
{ id: 34523, baz: 1},
{ id: 6435, baz: 4},
{ id: 3123, baz: 6},
...
];
When trying to retrieve specific data parts by ID from these arrays, it becomes slow as manual search is required. However, iteration speed over all data parts is fast.
Is there a way to achieve both fast direct access and rapid iteration?