In javascript we can't use key/value pairs in objects if they should keep their sort order. Instead we need an array with something like ES6 map for it.
It seems like the below could be one way to structure it. I put id and wrap all the items into an array. The same idea for the col blocks.
[
{
id: 21,
items: [
{
col: 'name',
data: {
data1: 'hello',
data2: 'world'
}
},
{
col: 'slug',
data: {
data1: 'hello',
data2: 'world'
}
}
]
},
{
id: 44,
items: [
{
col: 'name',
data: {
data1: 'hello',
data2: 'world'
}
},
{
col: 'slug',
data: {
data1: 'hello',
data2: 'world'
}
}
]
},
]
The problem
The problem with this approach is that when it can't use key/value pairs, then it needs to go through the whole array to find id 44 for example. In real life there are not just two groups, there can be a 100. The same thing with the cols. It may be 20 cols in each items group. It needs to walk through all of the items to find for example the column slug.
Dreamcode
let result = get(44, 'slug', 'data2');
Question(s)
- Is the structure above a good and performant one?
- How can I step in this without performace hits?