Here is an array of nested objects:
var existingArray = [{
"content": {
"host": {
"name": "Mia"
}
},
}, {
"content": {
"host": {
"name": "Annie"
}
},
}, {
"content": {
"host": {
"name": "Mia"
}
},
,
{
content: {
host: {
name: "Oscar"
}
},
},
{
"content": {
"host": {
"name": "Annie"
}
},
},
{
"content": {
"host": {
"name": "Mia"
}
},
},
{
"content": {
"host": {
"name": "Annie"
}
},
}
];
If I need to modify the object's name value when they match, how would I do it?
To create a new array like this:
var existingArray = [{
"content": {
"host": {
"name": "Mia"
}
},
}, {
"content": {
"host": {
"name": "Annie"
}
},
}, {
"content": {
"host": {
"name": "Mia_2"
}
},
,
{
content: {
host: {
name: "Oscar"
}
},
},
{
"content": {
"host": {
"name": "Annie_2"
}
},
},
{
"content": {
"host": {
"name": "Mia_3"
}
},
},
{
"content": {
"host": {
"name": "Annie_3"
}
},
}
];
The goal is to maintain the array structure almost the same, with only changes made to duplicate name values.
This adjustment is necessary because a plugin I am using identifies and merges duplicate names (the details are too complex to explain here).