So i currently have 2 arrays:
const getUniqueRowErrors = [1,3]
const data = [
{identifier: '000'},
{identifier: '111'},
{identifier: '222'},
{identifier: '3333'},
{identifier: '444'}
]
The idea is i want to remove the the elements based off the getUniqueRowErrors
, so I want the 1st,and 3rd element removed from the the data
array, so the end result being:
const data = [
{identifier: '111'},
{identifier: '3333'},
{identifier: '444'}
]
I tried the following but the desired result is incorrect:
const filteredData = getUniqueRowErrors.map((rowToRemove) => data.splice(rowToRemove));
Any ideas how to do the above?
>Solution :
Simply filter by index and check if the index is in the row errors array:
const getUniqueRowErrors = [1,3]
const data = [
{identifier: '000'},
{identifier: '111'},
{identifier: '222'},
{identifier: '3333'},
{identifier: '444'}
];
console.log(data.filter((_, i) => !getUniqueRowErrors.includes(i + 1)));