I am trying to figure out what is the best way to store and access data in javascript.
I want to select the data associated with a "identifier" who´s value is unknown before, or add a new data set with a new random "identifier".
do i do this with an array or object?
array storage
{
"data": [
{
"key1": "identfifier1",
"key2": "value2",
"key3": "value3"
},
{
"key1": "identfifier2",
"key2": "value2",
"key3": "value3"
}
]
}
- arrays stay orderd in js. this is important for me becuase i want to display its data on screen.
- more complicated selection of data set asscoictated with "identifier" (some kind of loop or containing helper method is needed, e.g. data.containing("identifier").key2)
object storage
{
"data": {
"identfifier1": {
"key1": "value1",
"key2": "value2",
"key3": "value3"
},
"identfifier2": {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
}
}
- objects do not stay orderd in js, but that is important for me becuase its data to display on screen ( i would have to sort the whole object before each output of the data )
- easy and fast selection of data asscoictated with "identifier" (just do identfifier1.key2 for expample, no loop or helper method nedded to search for data set containing "identifier")
any ideas, methods, best ways to do this? one way better than the other?