I've been searching for an answer but I'm not quite sure if I'm explaining the question properly to find the right answer. So essentially I have an array of many objects with much of the data being identical, I would like to condense the objects down to handle the data better
So I currently have something like:
var inStock =[
{"colour":"blue","type":"xs","item" : "shirt"},
{"colour":"blue","type":"xs","item" : "socks"},
{"colour":"pink","type":"xs","item" : "shirt"},
{"colour":"pink","type":"xl","item" : "socks"},
{"colour":"pink","type":"xl","item" : "shoes"}
];
and I would like to write some JS to convert it to something like:
var inStock = [
{
"colour":"blue",
"type":{
"xs",["shirt","socks"]
}
},
{
"colour":"pink",
"type":{
"xs":["shirt"],
"xl":["socks","shoes"]
}
}
];
I am essentially trying to organise the data into some sort of hierarchal system to organise the data better. I'm not sure if there is even a way to do this - but I'm open to other organisational suggestions that can help with condensing down the data.