Returns the substring before the first occurrence of the delimiter.
String (or null/undefined) to find the substring of.
null
undefined
Needle that marks where the cropped string should end.
Optional
Value to return when s is nullish or delimiter is not found (defaults to null).
s
delimiter
on_missing
substringBefore("path/to/file.txt", '/'); // "path"substringBefore("abc123xyz", /\d+/); // "abc"substringBefore(undefined, ':'); // nullsubstringBefore("no-needle", ':'); // nullsubstringBefore("no-needle", ':', 'default'); // 'default'substringBefore(null, ':', ''); // '' Copy
substringBefore("path/to/file.txt", '/'); // "path"substringBefore("abc123xyz", /\d+/); // "abc"substringBefore(undefined, ':'); // nullsubstringBefore("no-needle", ':'); // nullsubstringBefore("no-needle", ':', 'default'); // 'default'substringBefore(null, ':', ''); // ''
Returns the substring before the first occurrence of the delimiter.