I am trying to print a list of persons that share same address and company name My array:
persons = [
{ address: "Wallstreet",
company: "ABC",
name: "John",
telephoneNr: "12345"
},
{ address: "Wallstreet",
company: "ABC",
name: "Rick",
telephoneNr: "12857"
},
{ address: "Wallstreet",
company: "ABC",
name: "Eva",
telephoneNr: "38665"
}
]
I am using map function, but I want to print address and company name only once, since they all share same address and same company. How can I skip printing addresses and company name for the second, third and n time in the loop?
{persons.map((item, index) => {
return (
<p>
{item.address}
</p>
<p>
{item.company}
</p>
<p>
{item.name}: {item.telephoneNr}
</p>
)})}
My print looks like this:
Wallstreet
ABC
John:12345
Wallstreet
ABC
Rick:12857
Wallstreet
ABC
Eva: 38665
And I want my print to look like this:
Wallstreet
ABC
John:12345
Rick:12857
Eva: 38665