I am looking to structure my data in the following way:
Category 1
- Company 1
- Company 2
- Company 3
Category 2
- Company 1
- Company 2
- Company 3
Below is my code snippet:
getlist() {
var list = this.lists;
var category
this.$http.get("/getlist")
.then((res) => {
var obj = res.data;
for(var [key] in obj) {
var company =[];
for(var i in obj[key].company) {
company.push( obj[key].company[i].name)
}
console.log(company);
list.push({
"category_name" : obj[key].name,
"companies": [
{name: company}
]
})
list.category_name = '',
list.companies = '',
company= ''
}
})
},
The structure of my list should appear as follows:
{
category_name: 'Category1',
companies: [
{name: 'Company1'},
]
},
Here is an example of how the data should look:
[
{
"name": "Category2",
"company": [
{
"name": "Company1"
}
{
"name": "Company2"
}
]
}
{
"name": "Category2",
"company": [
{
"name": "Company1"
}
{
"name": "Company2"
}
]
}
]
Is it possible to use a double for loop
within list.push()
?
This problem is proving to be quite challenging for me.