I have an array of objects with a position property along with other properties like this:
[{position: 1, ...otherProperties}, ...otherObjects]
In the frontend, the objects are displayed and sorted by their position.
I am looking for JavaScript functions to perform the following operations:
- Insert a new object at a specified position (e.g., before the element with position: 1) and update the positions of the other elements accordingly (e.g., previous position: 1 element will now be position: 2).
- Delete an object from a specified position and update the positions of the remaining elements accordingly.
I am struggling with the creation of these functions