I have two arrays of objects
array = [
{
"id_0":356,
"name":"India",
"key1":150
},
{
"id_0":356,
"name":"India",
"key2":200
},
{
"id_0":748,
"name":"Swaziland",
"key1":140
},
{
"id_0":748,
"name":"Swaziland",
"key2":180
}
]
I am trying to find the duplicate id_0 in array of objects and merge the duplicate object of key2 and value.
I want the result to be:
array = [
{
"id_0":356,
"name":"India",
"key1":150,
"key2":200
},
{
"id_0":748,
"name":"Swaziland",
"key1":140,
"key2":180
}
]
How to find the duplicate value and merge the duplicate key and value in array?
namebecomesindiafromIndia, also, what if the dupls have same attribute, what did you expect its outcome, for example, if the first item also haskey2: 123, what will the result be?