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
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-substring-before-specific-character
Get the Substring before a specific Character in JavaScript | bobbyhadz
If your string contains multiple occurrences of the character and you need to get the substring up to the last occurrence of the character, use the String.lastIndexOf() method instead.
🌐
The Valley of Code
thevalleyofcode.com › js-get-string-until-character
JavaScript, how to get string until character
I needed to get the first part of a string. Basically everything before a specific character, -.
🌐
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
If 'pos' is neither 'a' nor 'b', it returns the original string. The function is tested with two examples using console.log, demonstrating how to extract substrings before and after specific characters. ... See the Pen JavaScript Get a part of string after a specified character - string-ex-22 by w3resource (@w3resource) on CodePen.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-substring-after-specific-character
Get the Substring after a specific Character in JavaScript | bobbyhadz
The indexOf() method returns the index of the first occurrence of the character and we use the String.slice() method to get a slice of the string after the character. You can learn more about the related topics by checking out the following ...
🌐
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
Find elsewhere
🌐
CopyProgramming
copyprogramming.com › howto › javascript-javascript-get-string-before-and-after-character
JavaScript: Get String Before and After Character
December 8, 2025 - Modern Feature: Use array.at(-1) to easily grab the text after the last instance of a character (like file extensions). Safety: Always check if the separator exists (indexOf !== -1) before slicing to prevent unexpected results. Q: What happens if the character isn't found in the string?
🌐
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 ...
🌐
Sabe
sabe.io › blog › javascript-get-substring-after-specific-character
Get the Substring after a Specific Character in JavaScript
May 10, 2022 - To get this, we can use the built-in string method indexOf(). This method takes a character and returns the index of that character, which is the number of characters before the character.
🌐
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-last-occurrence-in-a-string-in-javascript-or-node-js
Get the Part Before Last Occurrence in a String in JavaScript or Node.js
Using the array of split parts allows you to retrieve the portion before the last occurrence of a character or character sequence. In this case, you want all parts of the array except the last one. Here’s a beforeLast utility function returning the part before the last occurrence of a given ...
🌐
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
🌐
Logfetch
logfetch.com › js-get-substring-before-char
How to Get the Substring Before a Character in JavaScript - LogFetch
In str.split(":"), the parameter acts as a delimiter in the string, and each element is returned inside an array.
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method does not change the original string. If start is greater than end, arguments are swapped: (4, 1) = (1, 4). Start or end values less than 0, are treated as 0. ... If you want to use W3Schools services as an educational ...