Unhandled Runtime Error TypeError: data.filter is not a function in React application
I'm trying to filter data object with some condition but it is throwing the below error in my react application
Unhandled Runtime Error
TypeError: data.filter is not a function
What's wrong here?
1 Answer
4 years ago by Jahaan
filter() method works only on arrays. Make sure data is an array to apply filter() method.
Most commonly, we pass object data instead of array which causes this error. In order to convert objects to arrays, you can use any of the below methods based on your requirement.
1. Object.keys(data)
Creates an array consisting of all the keys present in the object
2. Object.values(data)
Creates an array consisting of all the values present in the object
3. Object.entries(data)
Creates an array consisting of both the keys and values present in the object
4 years ago by Divya