If you want to extract all the characters from a string before a character, you can use the substr() or substring() functions.

For example, if you want to extract the civic number from an address, there are 3 ways you can get the substring.

1- Using substr()

const address = '100 Queen St W, Toronto, ON M5H 2N2';
const civicNumber = address.substr(0, address.indexOf(' '));

2- Using substring()

const address = '100 Queen St W, Toronto, ON M5H 2N2';
const civicNumber = address.substring(0, address.indexOf(' '));

3- Using split()

const address = '100 Queen St W, Toronto, ON M5H 2N2';
const civicNumber = address.split(' ')[0];