I am trying to Remove Duplicate Objects From Javascript Array.
I have a object like this
var actualObj = [
{
"name": "Sam",
"id": "1",
"dept": "Inventory",
"info": {
"key1": "test1",
"key2": "test2",
"key3": "test3"
}
},
{
"name": "Paul",
"id": "2",
"dept": "Inventory",
"info": {
"key1": "test1",
"key2": "test2",
"key3": "test3"
}
},
{
"name": "Sam",
"id": "1",
"dept": "Inventory",
"info": {
"key4": "test4",
"key5": "test5",
"key6": "test6"
}
}
]
where I am trying to remove duplicates and combine the "info" into object array, something like this
var expectedObj = [
{
"name": "Sam",
"id": "1",
"dept": "Inventory",
"info": [
{
"key1": "test1",
"key2": "test2",
"key3": "test3"
},
{
"key4": "test4",
"key5": "test5",
"key6": "test6"
}
]
},
{
"name": "Paul",
"id": "2",
"dept": "Inventory",
"info": {
"key1": "test1",
"key2": "test2",
"key3": "test3"
}
}
]
With same value in "info" object, I tried with Lodash which works fine JSFIDDLE
Can anyone help me in achieving the expected object from the actual object. I am trying to create expected object by Combining as one object with similar id value.