Let's consider the following scenario:
let arr1 = [0,2] // This array is always sorted
Just to clarify, these elements in the "arr1" array represent indexes that need to be removed from another array.
We also have another array:
let arrOvj = [1,4,6,7,21,17,12]
The goal here is to remove elements from "arrObj" based on the indexes present in "arr1".
After the deletion process, we expect the output to be:
[4,7,21,17,12].
Now, the attempted solution was using a loop to splice out elements like this:
for(let i=0;i<arr1.length;i++){
arrObj.splice(arr1[i],1)
}
However, this method provided incorrect results. For instance, if "arr1"=[0], it deleted the first two elements instead of just removing the element at index 0 of "arrObj".
Do you know of an alternate approach I can take to ensure removal only occurs at the specified index values?
Feel free to request more information if needed.