Copyright 2025

The Valley of Code

A Flavio Copes project

JavaScript, how to get string until character
JavaScript, how to 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:

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

Want to master TypeScript? Check out my TypeScript Masterclass

Join my AI Workshop !

The Web Development BOOTCAMP cohort starts in February 2026