I tried to delete an array of array within an array if certain values existed
But I am getting this error
Error: Uncaught TypeError: data.every() is not a function
code below -- which worked for me in an online compiler
const data = [
['true', 'visiting-today', 'DVM-Wiessman', 'J-001'],
['false', 'visiting-tommorrow', 'DVM-Stevens', 'K-001'],
['true', 'visiting-tommorrow', 'DVM-Stevens', 'Z-001'],
['false', 'visiting-tommorrow', 'DVM-Kon', 'J-001']
]
const del_values = ['J-001', 'K-001'];
function remove_from_list(list, deleted_values) {
return list.filter(data => data.every(el => !deleted_values.includes(el)))
}
console.log(remove_from_list(data, del_values))
I have also tried replacing includes with .indexOf() and .includes() but also get a similar error
Uncaught TypeError: data.indexOf is not a function
Uncaught TypeError: data.includes is not a function
CodePudding user response:
The code you've provided works, you can test it in your browser's console.
The problem is you're trying to use Array methods on a variable that isn't an Array, so it's not recognizing those functions. if you're returning an answer with Fetch API make sure you add await/async or .then().
