I am trying to filter an array A while slicing an array B using the index in the callback function filter.
const endResult = answers[user].filter((ans, index) => {
if (ans !== '') {
return true
} else {
console.log(index)
outsideArray.splice(index, 1)
return false
}
})
It seems I can't use the index inside the filter callback function to splice another array. Is there a way to do this? I tried various things like map() without much success.
outsideArray: Array [ 1, 2, 4, 5 ]
answer[users]: Array [ "fff", "", "", "fffffff", "", "" ]
In the end, I get:
outsideArray: Array [ 1, 4 ]
answer[users]: Array [ "fff", "fffffff" ]
I should get:
outsideArray: Array [ ]
answer[users]: Array [ "fff", "fffffff" ]
outsideArrayto look after the operation has finished ??