[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Array](https://evolu.dev/docs/api-reference/common/Array) › filterArray

## Call Signature

```ts
function filterArray<T, S>(
  array: readonly T[],
  refinement: RefinementWithIndex<T, S>,
): readonly S[];
```

Defined in: [packages/common/src/Array.ts:465](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Array.ts#L465)

Filters an array using a predicate or refinement function, returning a new
readonly array.

When used with a refinement function (with `value is Type` syntax),
TypeScript will narrow the result type to the narrowed type, making it useful
for filtering with Evolu Types like `PositiveInt.is`.

### Example

### With predicate

```ts
filterArray([1, 2, 3, 4, 5], (x) => x % 2 === 0); // [2, 4]
```

### With refinement

```ts
const mixed: ReadonlyArray<NonEmptyString | PositiveInt> = [
  NonEmptyString.orThrow("hello"),
  PositiveInt.orThrow(42),
];
const positiveInts = filterArray(mixed, PositiveInt.is);
// positiveInts: ReadonlyArray<PositiveInt> (narrowed type)
```

## Call Signature

```ts
function filterArray<T>(
  array: readonly T[],
  predicate: PredicateWithIndex<T>,
): readonly T[];
```

Defined in: [packages/common/src/Array.ts:470](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Array.ts#L470)

With predicate.