I have an array in my state called columnToFilterOut. Let's say this is my array in my state: columnToFilterOut = ["first_col", "second_col", "third_col"]
I also have another array in state called rows that contains a list of dicts where there is a key called id that is corresponding to the values in columnToFilterOut. Here is an example of rows:
rows: [
{
id: "first_col",
numeric: false,
disablePadding: true,
label: "1"
},
{
id: "second_col",
numeric: true,
disablePadding: false,
label: "2"
},
{
id: "third_col",
numeric: true,
disablePadding: false,
label: "3"
},
{
id: "fourth_col",
numeric: true,
disablePadding: false,
label: "4"
}
]
As you can see, there is an extra element in there. The extra value is the one with id = "fourth_col". I want to delete all elements to make sure that both arrays match up.
Here is my delete function:
removeFromRowsById(id) {
console.log("IN REMOVE FUNCTION");
const filteredValues = this.state.rows.filter((_, i) => i["id"] !== id);
this.setState({ rows: filteredValues });
}
So I pass in an id and it should remove the value with the given id. Inside my render function, I use it like this:
Object.keys(rows).map(
(key, index) =>
!(columnToFilterOut.indexOf(rows[index]["id"]) > -1) //meaning the value doesn't exist inside of columnToFilterOut
? this.removeFromRowsById.bind(this, rows[index]["id"])
: console.log("Not deleting")
);
This isn't working. The value in the rows array is never removed. I print it to make sure. I also notice that my print statement inside of removeFromRowsById never logs to the console as though the function never actually gets called. Any help is great. Thanks!