I have two arrays as follows:
array1: [c,d,e]
array2: [[a,b,c,d,e], [1,2,3,4,5], [6,7,8,9,10]]
I have given an input which is [c,d,e].
What I want to achieve is remove all the corresponding index elements in array2 as shown below and only keep elements which have indices corresponding to [a,b] (In this case 0 and 1) and [c,d, e] needs to be removed, which is [3, 4, 5].
so the resultant output should be:
array2: [[a,b], [1,2], [6,7]]
Treat array2 as a table where 0th element is always going to be the header and rest all the data. Here it's not necessary that the array1 will have consecutive elements (like c,d and e) it can be (c, a, e) as well.
I was using:
x.forEach(elem => {
l.forEach(index => {
elem.splice(l,1);
})
})
But problem with this approach is that each time it slices out one element their relative position changes and hence gives out the wrong results. Any better and accurate way of doing so?