Add a field array argument for the filter, so that it is not hardcoded anymore.
Technicaljunior full stack developerBackend DeveloperTo add a field array argument for the filter, I would modify the function signature to accept an array parameter, say fields. Then, I would use Array.prototype.filter() to iterate over the data and check if each item contains any of the specified fields.
This approach makes the filter more dynamic and reusable. For example, I could implement it like this:
- Check if the item matches any field in the fields array.
- Return the filtered results based on that condition.
This way, we avoid hardcoding and enhance flexibility.