Here is an example of an array of objects:
"followers": [
{
"id": "1be87842-2f7f-4e3b-8fde-9a998feb3a01",
"bug_id": "4ae2707b-07ef-4e07-95da-77855c67fece",
"user_id": "e9e81aa2-4994-483d-a3a7-3b88491f1fda",
"username": "texample1",
"name": "Test Example1",
"created_at": "2018-11-27 21:01:42",
"updated_at": "2018-11-27 21:01:42",
"deleted_at": null
},
{
"id": "7bd1fa5f-4109-4beb-b53a-fb03a1d23536",
"bug_id": "4ae2707b-07ef-4e07-95da-77855c67fece",
"user_id": "e9e81aa2-4994-483d-a3a7-3b88491f1fda",
"username": "texample1",
"name": "Test Example2",
"created_at": "2018-11-27 21:01:48",
"updated_at": "2018-11-27 21:01:48",
"deleted_at": null
}
]
In my vuex store, I have code that attempts to remove an object by its index from the above array:
let followersArray = state.bugs.find(b => b.id === follower.bug_id).followers
let index = followersArray.indexOf(follower)
followersArray.splice(index, 1)
When passing a follower object to this mutation function, it finds the followers array in a bug object, locates the index of the follower, and attempts to remove it. However, the index logged is -1 instead of 1. Any idea what may be causing this issue? If I had the correct index, I would include a condition like if(index !== -1)
.