You can make use of Array.prototype.splice()
:
const addressName = "My Business, 123 Main Street, Vancouver, BC, Canada";
const provinces = addressName.split(',').slice(2).join(',');
console.log(provinces);
You can make use of Array.prototype.splice()
:
const addressName = "My Business, 123 Main Street, Vancouver, BC, Canada";
const provinces = addressName.split(',').slice(2).join(',');
console.log(provinces);
Try this:
var addressName = "My Business, 123 Main Street, Vancouver, BC, Canada"
var output = addressName.split(",").slice(2).join(",")
console.log(output)
I am looking to pull the city, province/state and country from a address field and I want to remove the business name and street name before as follows:
addressName = "My Business, 123 Main Street, Vancouver, BC, Canada"
I want to capture this:
output = "Vancouver, BC, Canada"
I have tried splitting the array using the comma as the entry point although in that case I only get one of the three pieces of information that I need and I have done so in order to capture just the business name in a separate field. Will I need to have a range for the array to go through? Any help is appreciated, thank you!
addressName.split(',').slice(2).join(',').trim()
That makes sense, thank you very much!
You split using comma and remove the first two elements. Once again you join.
"My Business, 123 Main Street, Vancouver, BC, Canada".replace(/(.+, )([^,]+,[^,]+,[^,]+)$/, '$2')
IDidn’tDownVote