JavaScript, how to get string until character
By Flavio Copes
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.
~~~
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' ~~~
Related posts about js: