I encountered a situation similar to the one described in this post here, where I not only want to retrieve an element but also change its name value.
I came across a method that involves using splice:
dataList.splice(index, 1);
dataList.splice(index, 0, newItem);
However, there are some issues with this approach. It becomes challenging to keep track of the index <=> id correlation when manipulating the array regularly. Removing items, changing them, and pushing them back as "new" ones may not be the most elegant solution and could potentially lead to problems.
Essentially, all I want to do is toggle a visible attribute within the array. Here's an example of the array:
$scope.cLines = [{ id: 1, cColor: 'red', cName: 'Entryline right', visible: true }];
Although there are usually more elements present, I have simplified it for clarity.
The desired functionality of the visible toggler can be outlined in the following pseudo-code:
$scope.cLines[id === id].visible = !$scope.cLines[id === id].visible;
Alternatively, it would be great if I could directly access the element using a filter. Is that achievable?
Thank you for your assistance.