[Home](./index.md) > [@csstools/css-parser-algorithms](./css-parser-algorithms.md) > [forEach](./css-parser-algorithms.foreach.md) ## forEach() function Iterates over each item in a list of component values. **Signature:** ```typescript export declare function forEach>(componentValues: Array, cb: (entry: { node: ComponentValue; parent: ContainerNode | { value: Array; }; state?: T; }, index: number | string) => boolean | void, state?: T): false | undefined; ``` ## Parameters
Parameter Type Description
componentValues Array<[ComponentValue](./css-parser-algorithms.componentvalue.md)>
cb (entry: { node: [ComponentValue](./css-parser-algorithms.componentvalue.md); parent: [ContainerNode](./css-parser-algorithms.containernode.md) \| { value: Array<[ComponentValue](./css-parser-algorithms.componentvalue.md)>; }; state?: T; }, index: number \| string) => boolean \| void The callback function to execute for each item. The function receives an object containing the current node (`node`), its parent (`parent`), and an optional `state` object. A second parameter is the index of the current node. The function can return `false` to stop the iteration.
state T _(Optional)_ An optional state object that can be used to pass additional information to the callback function. The state object is cloned for each iteration. This means that changes to the state object are not reflected in the next iteration.
**Returns:** false \| undefined `false` if the iteration was halted, `undefined` otherwise.