# JavaScript, how to get string until character

> Learn how to get the part of a string before a specific character in JavaScript using split, a quick one-liner that returns everything up to that point.

Author: Flavio Copes | Published: 2022-07-24 | Canonical: https://flaviocopes.com/js-get-string-until-character/

I needed to get the first part of a string. 

Basically everything before a specific character, `-`. 

Here's how I did it:

```js
const str = 'test-hey-ho'
str.split('-')[0] //'test'
```
