Having 2 arrays:
var alleditvals= {username: "twooooo", password: "two_p", address: "two_add"};
var a= {username: "two", password: "two_p", address: "two_add"};
My goal is to replace only the difference ("twoooo") into the object a
, making it similar to alleditvals
.
In my code, a
comes from an array named add_data
, hence I utilize the map
function:
add_data.map((a,i)=>
i===count_edit ? alleditvals : a
)
where count_edit
gets updated as a number. By checking if the index of add_data
corresponds to count_edit
, I include the value of alleditvals
, otherwise retain the value in add_data
(which is a
). The challenge with this approach is that it replaces every object inside add_data
when the condition holds true, including fields like password
and address
. Could you please suggest a method where I can selectively replace only the item that has changed?
Appreciate your help.