Home:ALL Converter>split address to streetNumber, streetName and streetType

split address to streetNumber, streetName and streetType

Ask Time:2016-05-24T21:52:05         Author:Medo

Json Formatter

Here the jsBin Here in code if you don't want to click on the link

var parseString = function (s) {
  var streetNumber = s.split(' ')[0];
  var streetName = s.split(' ')[1];
  var streetType = s.split(' ')[2];

  return {
    streetNumber: streetNumber,
    streetName: streetName,
    streetType: streetType,
  };
};
var address = "1498 Riedel Street";

console.log("Street Number: " + parseString(address).streetNumber);
console.log("Street Name: " + parseString(address).streetName);
console.log("Street Type: " + parseString(address).streetType);

address =  "4860 Dry Pine Bay Rd"

console.log("Street Number: " + parseString(address).streetNumber);
console.log("Street Name: " + parseString(address).streetName);
console.log("Street Type: " + parseString(address).streetType);

Now I want to split address in Number, Name and Type.

StreetType is following specific ISO format and is always found as last in the string.

The problem is when the Street Name have multiple spaces. How can I split StreetName with multiple characters from the street Type

Author:Medo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37415685/split-address-to-streetnumber-streetname-and-streettype
Mateusz :

You can try\n\nvar address = \"4860 Dry Pine Bay Rd\";\nvar split = address.split(\" \");\nvar number = split[0];\nvar name = split[1];\nfor (var i = 2; i < split.length - 1; i++)\n name += \" \" + split[i];\nvar type = split[split.length - 1];\n\n\nThis assumes that street type does not contain spaces.\n\nAlternatively you can use slice() and then join().\n\nvar name = split.slice(1, split.length - 1).join(\" \");\n\n\nThis takes a subarray of split (excludes the first and the last element) and joins the subarray on the space.",
2016-05-24T13:54:17
yy