I am trying to extract everything before the ',' comma. How do I do this in JavaScript or jQuery? I tried this and not working..
1345 albany street, Bellevue WA 42344
I just want to grab the street address.
var streetaddress= substr(addy, 0, index(addy, '.'));
You can use Azle to get substrings before:
Result: This is how we go to the
after
Result: to the place!
and in between:
Result: we go to the
You can also use
shift()
.According to MDN Web Docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
Also, I'd recommend naming your variables with camel-case(streetAddress) for better readability.
If you want to return the original string untouched if it does not contain the search character then you can use an anonymous function (a closure):
This can be made more generic:
If you like it short simply use a RegExp:
(You should read through a javascript tutorial, esp. the part about String functions)