I have two arrays. The first array contains some values while the second array contains indices of the values which should be removed from the first array. For example:
You can correct your code by replacing removeValFromIndex with removeValFromIndex.reverse(). If that array is not guaranteed to use ascending order, you can instead use removeValFromIndex.sort(function(a, b) { return b - a }).