I have the following array object
Here is the array
tagGroups: Array(6)
[
{name: "Function", tags: Array(1)}
{name: "Function", tags: Array(1)}
{name: "Function", tags: Array(1)}
{name: "Test", tags: Array(1)}
{name: "Test", tags: Array(1)}
{name: "new", tags: Array(1)}
]
I need to be able to merge the tags array with the same name of object so I would end up with the following
{
"name": "Tag Group 1",
"tags": [
"TagA",
"TagB",
"TagC"
]
},
This is my correct code, which creates the object format
// Creates the final format that can be upload or stored
for (var i = 0, l = tagGroupsArr.length; i < l; i++) {
tagGroupsTemp = {name: tagGroupsArr[i].tagGroupName, tags: [tagGroupsArr[i].tag]};
tagGroupsFinal.push(tagGroupsTemp);
}
See Question&Answers more detail:os