let dates = {
'2018/07/25': [['1','red'], ['1','orange'], ['3','blue']],
'2018/07/26': [['2','black'], ['4','orange'], ['4','pink']],
'2018/08/01': [['3','purple'], ['4','green']]
}
The newObject expected is:
newObject = {
'2018/07':{
'2018/07/25': {
'1':['red','orange'],
'3':['blue']
},
'2018/07/26': {
'2':['black'],
'4':['orange','pink']
}
},
'2018/08':{
'2018/08/01': {
'3':['purple'],
'4':['green']
}
}
}
My code so far:
let newObject = {};
Object.keys(dates).forEach((onedate, index) => {
let monthdate = onedate.slice(0,7)
if (!newObject[monthdate]) {
newObject[monthdate] = {};
}
newObject[monthdate][onedate] = [...dates[onedate]];
});
The output of above code:
newObject = {
"2018/07":{
"2018/07/25": [["1","red"],["1","orange"],["3","blue"]],
"2018/07/26": [["2","black"],["4","orange"],["4","pink"]]
},
"2018/08":{
"2018/08/01": [["3","purple"],["4","green"]]
}
}
I want to remove array in level 3 depth too. Also separate the first number maybe using Sets and have their respective relation to colors
"2018/07/25": [["1","red"],["1","orange"],["3","blue"]]
to
'2018/07/25': {'1':['red','orange'],'3':['blue']}