[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: (item: T, index: number, array: readonly T[]) => item is S,
): readonly S[];
```

Defined in: [packages/common/src/Array.ts:639](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Array.ts#L639)

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`.

### With predicate

```ts

const evens = filterArray([1, 2, 3, 4, 5], (x) => x % 2 === 0);
assertEqual(evens, [2, 4]);
```

### With refinement

```ts
import {
  assertEqual,
  assertType,
  filterArray,
  NonEmptyTrimmedString,
  PositiveInt,
} from "@evolu/common";

const mixed: ReadonlyArray<NonEmptyTrimmedString | PositiveInt> = [
  NonEmptyTrimmedString.orThrow("hello"),
  PositiveInt.orThrow(42),
];
const positiveInts = filterArray(mixed, PositiveInt.is);
assertEqual(positiveInts, [42]);
assertType<ReadonlyArray<PositiveInt>, typeof positiveInts>();
```

The predicate receives `(item, index, array)`, matching native
`Array.filter`.

## Call Signature

```ts
function filterArray<T>(
  array: readonly T[],
  predicate: (item: T, index: number, array: readonly T[]) => boolean,
): readonly T[];
```

Defined in: [packages/common/src/Array.ts:644](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Array.ts#L644)

With predicate.