---
title: "Comment by Ákos Kőműves on \"Build a search bar with filter in React - Part 1\" | Hashnode"
description: "Thanks for sharing the complete solutions! There are functional alternatives to forEach, for and other array operations. For example, this code: let itemsAsList"
url: "https://hashnode.com/posts/build-a-search-bar-with-filter-in-react-part-1/638b3f46b61e22924272f475/comment/638b53d264b7288d8d8e414b"
---

[Discussion](https://hashnode.com/posts/build-a-search-bar-with-filter-in-react-part-1/638b3f46b61e22924272f475)

Comment [Build a search bar with filter in React - Part 1](https://hashnode.com/posts/build-a-search-bar-with-filter-in-react-part-1/638b3f46b61e22924272f475)

[Ákos Kőműves](https://hashnode.com/@akoskm)

[Dec 3, 2022](https://hashnode.com/posts/build-a-search-bar-with-filter-in-react-part-1/638b3f46b61e22924272f475/comment/638b53d264b7288d8d8e414b)

Thanks for sharing the complete solutions!

There are functional alternatives to forEach, for and other array operations.

For example, this code:

```
   let itemsAsList: string[] = [];

    itemsAsSet.forEach((v) => {
        if (v !== undefined && v !== null) itemsAsList.push(v);
    });

    return itemsAsList;
```

can be written as:

```
let itemsAsList = itemsAsSet.filter((v) =>
  v !== undefined && v !== null
));

return itemsAsList;
```
