This guy has a really nice method for splitting a string based on the first occurrence of a character in Javascript:
function splitFirstOccurrence(str, separator) {
const [first, ...rest] = str.split(separator);
const remainder = rest.join(separator);
return {first, remainder};
}
Calling this method can yield the first occurrence of a character, as well as the rest of the string as follows:
const result = splitFirstOccurrence('somedomain.co.za', '.');
console.log(result); // { first: 'somedomain', remainder: 'co.za' }
console.log(result.first); // somedomain
console.log(result.remainder); // co.za