1

I have just started programming with javascript. I am trying to work with arrays and I don't understand why I am getting a split is not a function error, when I try to split the content of the array like in the following code.

var addressArray=[[]];
/*
some code to pass values to the addressArray 

*/

var values=addressArray[i].split(/ ,+/);

the error is occuring where I am spliting

4
  • 4
    There's no .split() function for arrays. There is a String .split() however. It's hard to know what it is you want to do without actually seeing the stuff in your array. Commented Dec 4, 2014 at 20:42
  • in the array there phrase like: 1 housenumber street city, 2 hause number street city Commented Dec 4, 2014 at 20:46
  • Incidentally, that regex matches "exactly one space followed by one or more commas", which seems an odd thing to look for. But maybe it makes sense in your context. Commented Dec 4, 2014 at 20:47
  • yes there are commas and after each comma a space Commented Dec 4, 2014 at 20:59

1 Answer 1

3

You cannot split an array itself - split() is used to split a string into an array. I suspect you're attempting to split a string that is within an array, in which case you should be careful to index the string correctly. Looking at your declaration of addressArray:

var addressArray=[[]];

You seem to have nested arrays, in which case you will need to use two indices to refer to a string within an array, which is itself within addressArray; for example, addressArray[i][j].split(/ ,+/).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.