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
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
Share Improve this question edited Dec 4, 2014 at 20:42 Pointy 414k62 gold badges595 silver badges629 bronze badges asked Dec 4, 2014 at 20:41 akaAlsoakaAlso 1401 gold badge1 silver badge8 bronze badges 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. – Pointy Commented Dec 4, 2014 at 20:42 - in the array there phrase like: 1 housenumber street city, 2 hause number street city – akaAlso Commented Dec 4, 2014 at 20:46
- Incidentally, that regex matches "exactly one space followed by one or more mas", which seems an odd thing to look for. But maybe it makes sense in your context. – IMSoP Commented Dec 4, 2014 at 20:47
- yes there are mas and after each ma a space – akaAlso Commented Dec 4, 2014 at 20:59
1 Answer
Reset to default 3You 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(/ ,+/)
.