0
I have an object in JS with information of places (Cinema, Museum, etc.) that I will use to popular in my system. Example:
var places = {
"type": "ABC",
"features": [
{
"type": "AB",
"properties": {
"title": "Text 1",
"description": "Lorem ipsum 1",
"category": "Museu"
},
"optional": {
"type": "ZX",
}
},
{
"type": "AB",
"properties": {
"title": "Text 2",
"description": "Lorem ipsum 2",
"category": "Museu"
},
"optional": {
"type": "ZX",
}
},
{
"type": "AB",
"properties": {
"title": "Text 3",
"description": "Lorem ipsum 3",
"category": "Hotel"
},
"optional": {
"type": "ZX",
}
}
]
}
But now I need to break it into an object dividing by category, basically staying that way:
var variavel = {
{
category: "Museu",
places: {
type: "ABC",
features: [
{
"type": "AB",
"properties": {
"title": "Text 1",
"description": "Lorem ipsum 1",
"category": "Museu"
},
"optional": {
"type": "ZX",
}
},
{
"type": "AB",
"properties": {
"title": "Text 2",
"description": "Lorem ipsum 2",
"category": "Museu"
},
"optional": {
"type": "ZX",
}
},
]
}
},
{
category: "Hotel",
places: {
type: "ABC",
features: [
{
"type": "AB",
"properties": {
"title": "Text 3",
"description": "Lorem ipsum 3",
"category": "Hotel"
},
"optional": {
"type": "ZX",
}
},
]
}
}
}
What is the best way to achieve this? In this project there is no ES6.
What you’ve tried to do?
– Sam
Already have examples of many answers here with ES6, using
reduce,map,findIndexamong others. You have to use the same logic and transform these functions into their respective links.– Isac