There's so many of post here regarding merging javaScript array objects relative to my question most of them are merging 2 arrays in my case it's different.
I have JSON from API I mapped and filtered them because i only need the 'tags'
Here's my code:
JSON.map((key) => (key.tags))
.filter(function (element) {
return element !== undefined;
})
Here's my result:
[
{
"web_devt": {
"item_id": "858850847",
"tag": "web_devt"
}
},
{
"web_devt": {
"item_id": "1004644524",
"tag": "web_devt"
}
},
{
"pdo": {
"item_id": "1056300113",
"tag": "pdo"
},
"php": {
"item_id": "1056300113",
"tag": "php"
},
"web_devt": {
"item_id": "1056300113",
"tag": "web_devt"
}
},
{
"parallax scrolling": {
"item_id": "1087678088",
"tag": "parallax scrolling"
}
},
{
"react": {
"item_id": "2435593852",
"tag": "react"
}
},
{
"javascript": {
"item_id": "2435595088",
"tag": "javascript"
}
},
{
"react": {
"item_id": "2465629468",
"tag": "react"
}
}
]
I want to merge them like this:
[
{
"web_devt": [
item_id: "765558416",
item_id: "765558416",
item_id: "765558416",
...]
},
{
"react": [
item_id: "765558416",
item_id: "765558416",
item_id: "765558416",
...]
},
{
"JavaScipt": [
item_id: "765558416",
item_id: "765558416",
item_id: "765558416",
...]
}
]
and so on ... Basically all the same tags will merge How you do this in reduce or any solution but not loadash or any third party?