I am working with a state that fetches data from
https://jsonplaceholder.typicode.com/todos/
. My goal is to filter this data based on the status completed:true
or completed:false
.
Below is the method I am using to filter the array:
filterByStatus(status) {
const filteredResults = this.allTodos.filter(todo => todo.completed == status)
console.log(filteredResults)
}
When I pass true
or false
as a parameter to the method, console.log(filteredResults)
is returning an empty array.
filterByStatus(status) {
let filteredResults = [];
this.allTodos.map(item => {
if (item.completed == status) {
filteredResults.push(item);
}
});
console.log(filteredResults);
}
I also attempted to use the map method, but the result remains an empty array.
When I console.log(this.allTodos)
, the result is:
[{…}, {…}, {…}, {…}, {…}, __ob__: Observer]
Could this be due to the Observer?