---
title: "toPath"
description: "Parse a path string into an array of segments, supporting dot and bracket notation, the basis for safe nested property access."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/path/to-path"
---
# toPath

> Parse a path string into an array of segments, supporting dot and bracket notation, the basis for safe nested property access.

## Usage

`toPath` parses a path string into an array of segments.

```ts
import { toPath } from '@movk/core'

toPath('a.b[0].c') // ['a', 'b', 0, 'c']
toPath('a[\'x.y\']') // ['a', 'x.y']
```

## API

### `toPath(path)`

Parse a path string into an array of segments.

### Parameters

**path** (`PathInput`) *required*: A path string or array of segments.

### Returns

**returns** (`PathSegments`): The parsed array of path segments.

## Changelog

See commit history for [src/helpers/path/toPath.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/helpers/path/toPath.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/helpers/path/toPath.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
