I have an array that looks like this one(it has more items inside of it, but the structure is the same):
[
{
"users": [
"speciality": "surgery"
{
"name": "John",
"location": "USA",
"age": "34",
},
{
"name": "John",
"location": "California",
"address": "Silk Road 123"
},
{
"name": "Jane",
"last-name": "Edmus"
"location": "USA"
}
]
},
]
I´m trying to map this array in such a way that, if the name property is equal in two objects, it should get mapped as only one p tag with many locations appearing behind a "see more “tag”. This is what I currently have, which doesn´t work:
mapArray= () =>{
const test= this.state.test;
return test.map(i =>
i.users.map((user,index) =>
<div>
<p>{i.speciality}</p>
{user.name[index] ===user.name[index + 1] ? <p>{user}</p> <p>See more></p> <p>{user.location}} : <p>{user}<p>{user.location}</p>
</div>