最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - split is not a function on array - Stack Overflow

programmeradmin5浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 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(/ ,+/).

发布评论

评论列表(0)

  1. 暂无评论