Closed hafeefshaik closed 6 years ago
Hi, yes this happens when you add to the start of the array. compare
is working properly but not in the most optimized manner.
If you want to avoid this, please add to the end of the array, use push
not unshift
.
@alshakero as I am using angular 5 two way binding, I think it's bit hard to handle it. Is there any other work around?
I don't think so. If you compare the arrays manually:
"roles": [
"Developer",
"Admin"
]
and
"roles": [
"Admin",
"Business Analyst",
"Delivery Manager",
"Developer"
]
How would you explain the difference?
Closing for lack of response.
Original object :
{ "id": "06449690-3e21-43c9-0c13-08d5a8f9a4ff", "firstName": "Hafeef", "lastName": "Shaik", "roles": [ "Developer", "Admin" ] }
Later added couple of other roles. Modified object:
{ "id": "06449690-3e21-43c9-0c13-08d5a8f9a4ff", "firstName": "Hafeef", "lastName": "Shaik", "roles": [ "Admin", "Business Analyst", "Delivery Manager", "Developer" ] }
When I compare, I could see couple of replace action as mentioned below.
[ { "op": "replace", "path": "/roles/1", "value": "Business Analyst" }, { "op": "replace", "path": "/roles/0", "value": "Admin" }, { "op": "add", "path": "/roles/2", "value": "Delivery Manager" }, { "op": "add", "path": "/roles/3", "value": "Developer" } ]
Please correct me if I am wrong, What I believe there should be two add operation as I am adding two new roles to the object.