const streetAddress = addy.substring(0, addy.indexOf(","));

While it’s not the best place for definitive information on what each method does (MDN Web Docs are better for that) W3Schools.com is good for introducing you to syntax.

Answer from wheresrhys on Stack Overflow
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-string-exercise-22.php
JavaScript validation with regular expression: Get a part of string after a specified character - w3resource
// Define a function named subStrAfterChars with parameters str (input string), char (character to search for), and pos (position indicator). function subStrAfterChars(str, char, pos) { // If the position indicator is 'b' (before), return the ...
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-substring-after-specific-character
Get the Substring after a specific Character in JavaScript | bobbyhadz
Use the String.slice() method to get the substring after the specific character. ... Copied!const str = 'abc bobby_hadz.com'; const after_ = str.slice(str.indexOf('_') + 1); console.log(after_); // 👉️ "hadz.com" ...
🌐
TutorialsPoint
tutorialspoint.com › how-to-get-a-part-of-string-after-a-specified-character-in-javascript
How to get a part of string after a specified character in JavaScript?
To get a part of a string, string.substring() method is used in javascript. Using this method we can get any part of a string that is before or after a particular character. str.substring() This method slices a
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied. const str = "Mozilla"; console.log(str.substring(1, 3)); // Expected output: "oz" console.log(str.substring(2)); ...
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Find elsewhere
🌐
Linux Hint
linuxhint.com › get-substring-before-specific-character-javascript
Get the Substring Before a Specific Character in JavaScript
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Futurestud.io
futurestud.io › tutorials › get-the-part-before-first-occurrence-in-a-string-in-javascript-or-node-js
Get the Part Before First Occurrence in a String in JavaScript or Node.js
It provides a useful Str#before method returning the part of a string before the given character(s): const Str = require('@supercharge/strings') Str('Future Studio is an awesome island').before('is') // 'Future Studio ' Str('Future Studio is an awesome island').before('great') // 'Future Studio is an awesome island' Str('Future Studio').before() // 'Future Studio' That’s it! ... Get your weekly push notification about new and trending Future Studio content and recent platform enhancements
🌐
Futurestud.io
futurestud.io › tutorials › get-the-part-before-a-character-in-a-string-in-javascript-or-node-js
Get the Part Before a Character in a String in JavaScript or Node.js
const Str = require('@supercharge/strings') Str('A1:L200').before(':').get() // 'A1' Str('2020-this-is-a-tutorial-slug').before('-').get() // '2020' ... Get your weekly push notification about new and trending Future Studio content and recent platform enhancements
🌐
CopyProgramming
copyprogramming.com › howto › javascript-javascript-get-string-before-and-after-character
JavaScript: Get String Before and After Character
December 8, 2025 - Yes, all these methods (split, indexOf, replace) work exactly the same way with multi-character substrings (e.g., text.split('==')) as they do with single characters. Q: Is substring different from slice? Yes, but slice is generally preferred in modern JavaScript.
🌐
Logfetch
logfetch.com › js-get-substring-before-char
How to Get the Substring Before a Character in JavaScript - LogFetch
str = str.substring(0, str.indexOf(":")); str.indexOf(":") returns 4, so we are obtaining the string from index 0 (inclusive) to 4 (exclusive). str = /(.+):/.exec(str)[0]; (.+) matches any number of word characters. : matches, well, a colon. How to Validate a UUID with Regular Expressions in JavaScript ·
🌐
Refine
refine.dev › home › blog › tutorials › javascript substring method
JavaScript Substring Method | Refine
December 31, 2024 - Since we are using a zero-based index for startIndex, the first startIndex number of characters are represented by the index just before startIndex. And since the value at startIndex is included in the extracted tail, the following pattern emerges where with startIndex = n, we get the tail after first n characters in the parent string: const mnemonic = "Please, send, cats, monkeys, and, zebras, in, large, cages, make, sure, padlocked."; // Extract characters after first 14 console.log(mnemonic.substring(14)); // "cats, monkeys, and, zebras, in, large, cages, make, sure, padlocked."
🌐
Futurestud.io
futurestud.io › tutorials › get-the-part-before-last-occurrence-in-a-string-in-javascript-or-node-js
Get the Part Before Last Occurrence in a String in JavaScript or Node.js
/** * Returns the portion of the string before the last occurrence of the given `delimiter`. * * @param {String} delimiter * * @returns {String} */ function beforeLast (value, delimiter) { value = value || '' if (delimiter === '') { return value } const substrings = value.split(delimiter) return substrings.length === 1 ? value // delimiter is not part of the string : substrings.slice(0, -1).join(delimiter) } Notice: splitting a string for an empty delimiter creates an array of the string value’s characters.