I am working with an object array
const arr =
[
{ id: 1, name : "Joe", age:20, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed4d1dbfed6d1cad3dfd7d290ddd1d3">[email protected]</a>"},
{ id: 2, name : "Mike", age:50, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="325f5b5957725a5d465f535b5e1c515d5f">[email protected]</a>"},
{ id: 3, name : "Joe", age:45, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b535a4949427b53544f565a525715585456">[email protected]</a>"}
]
Is there a way to create a new array while keeping the first one intact but changing only one property, like this (id must remain unique):
[
{ id: 1, name : "Joe", age:20, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f55505a7f57504b525e5653115c5052">[email protected]</a>"},
{ id: 2, name : "Mike", age:50, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690400020c2901061d04080005470a0604">[email protected]</a>"},
{ id: 3, name : "Harry", age:45, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cda5acbfbfb48da5a2b9a0aca4a1e3aea2a0">[email protected]</a>"}
]
In the above example, I changed the name property of the last element from "Joe" to "Harry"