---
layout: page
---
# deepForEach()
Executes a provided function once on each child (and its children) on a children array.
```typescript
deepForEach(
children: ReactNode | ReactNode[],
forEachFn: (child: ReactNode, index?: number, children?: ReactNode[]): void,
): void
```
## Arguments
- children
- The children array from the element where is used.
- forEachFn
- Funcion to be called recursively each element (and its children) of the children array. Returns
undefined. It accepts three arguments:
-
- child
- The current child element being processed.
- index
- The index of the current child element being processed.
- children
- The children array that forEach was called upon.
## Return Value
`undefined`
## Example
```jsx
import React, { ReactElement, ReactNode } from 'react';
import { render } from 'react-dom';
import { deepForEach } from 'react-children-utilities';
interface Props {
children?: ReactNode;
}
const DeepForEached = ({ children }: Props): ReactElement => {
const items: ReactNode[] = [];
deepForEach(children, (child: ReactNode) => {
if (child && (child as ReactElement).type === 'b') {
items.push((child as ReactElement).props.children);
}
});
return {items}
;
};
const Example = (): ReactElement => (
1
2
3
non matching
example
);
render(, document.body)
// Result:
// 1234
```