In my JSON response, the structure is as follows:
{
data: [
{
attributes:[
{
type: 'size',
value: '10'
},
{
type: 'colour',
value: 'red'
}
],
inventory: [
{
store_id: '1000',
stock: '10'
},
{
store_id: '2000',
stock: '3'
},
{
store_id: '3000',
stock: '5'
}
]
},
{
attributes:[
{
type: 'size',
value: '9'
},
{
type: 'colour',
value: 'red'
}
],
inventory: [
{
store_id: '1000',
stock: '10'
},
{
store_id: '2000',
stock: '3'
},
{
store_id: '4000',
stock: '5'
}
]
},
{
attributes:[
{
type: 'size',
value: '7'
},
{
type: 'colour',
value: 'red'
}
],
inventory: [
{
store_id: '1000',
stock: '19'
},
{
store_id: '2001',
stock: '8'
},
{
store_id: '4000',
stock: '2'
}
]
}
]
}
With JavaScript, I am attempting to extract and sort the values based on store ID.
For example:
Considering the above data, here is what I aim to achieve:
array['2000'] = ['10 - (3)', '9 - (3)', '7 - (8)']
Here, 2000 represents the store_id and array values are in the format size - (stock)
.