I've been browsing through similar discussions, but I just can't seem to grasp the concept. The JSON data for my current item appears to be more complicated than I anticipated. Here is a snippet of the lengthy JSON data:
items = [
{
'name' : 'Books',
'types':[
{
'name' : 'Hard Cover',
'genres':[
{
'genre' : 'Romance',
'added_date' : '2018-09-15',
'id':1
},
{
'genre' : 'Crime',
'added_date' : '2018-10-01',
'id' : 2
}
],
'cover':['pic1.png','pic2.png']
},
{
'name' : 'Audio',
'genres':[
{
'genre' : 'Memoir',
'added_date' : '2018-08-01',
'id' : 3
}
],
'pictures':['pic3.png','pic4.png']
},
]
},
{
'name' : 'Videos',
'types':[
{
'name' : 'English',
'genres':[
{
'genre' : 'Comedy',
'added_date' : '2018-10-14',
'id' : 12
}
],
'pictures':['pic5.png','pic6.png']
}
]
}
];
What I'm aiming for now is to extract the 3 most recently added items based on their "added_date" within the "genres" block. For these items, I would like to generate an array with dictionary elements containing the full path information:
[
{'id':7,'genre':'Romance','name':'Hard Cover','added_date':'2018-09-16','top_parent_name':'Books'},
{'id':8,'genre':'Memoir','name':'Audio','added_date':'2018-09-15','top_parent_name':'Books'},
]
The goal is to identify and retrieve the latest 3 items added throughout the entire dataset based on their "added_date" field, along with relevant details. I hope this clarifies the objective.
So far, I have brainstormed some ideas, but implementing them has proven to be quite complex.
items.forEach(function(value, index, array) {
const types: any[] = value['types'];
types.forEach(function(value_t, index_t, array_t){
const genres: any[] = value_model['genes'];
//loop again to get date....
});
});