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

javascript - why does my array.join() not work as expected? - Stack Overflow

programmeradmin1浏览0评论

Safari 6:

> ['a=23', 'b=234', 'c=23'].join('&');
"a=23&b=234&c=23"

then with a variable I need to do this with. it's

jsss
  [
  Array[8]
    0: "s=1"
    1: "l=NTA4NTQzNnw0NzczOTg"
    2: "r=-1"
    3: "t=a"
    4: "m=0"
    5: "si=5156695"
    6: "u=5085436"
    7: "sn=mip"
    length: 8
    __proto__: Array[0]
   ]

> jsss.join('&');
"s=1,l=NTA4NTQzNnw0NzczOTg,r=-1,t=a,m=0,si=5156695,u=5085436,sn=mip"

Why does it seem to ignore the separator?

Safari 6:

> ['a=23', 'b=234', 'c=23'].join('&');
"a=23&b=234&c=23"

then with a variable I need to do this with. it's

jsss
  [
  Array[8]
    0: "s=1"
    1: "l=NTA4NTQzNnw0NzczOTg"
    2: "r=-1"
    3: "t=a"
    4: "m=0"
    5: "si=5156695"
    6: "u=5085436"
    7: "sn=mip"
    length: 8
    __proto__: Array[0]
   ]

> jsss.join('&');
"s=1,l=NTA4NTQzNnw0NzczOTg,r=-1,t=a,m=0,si=5156695,u=5085436,sn=mip"

Why does it seem to ignore the separator?

Share Improve this question asked Oct 6, 2012 at 19:34 ColeCole 1,5031 gold badge11 silver badges20 bronze badges 1
  • awesome. I've been out of this for a year and need to get back up to speed... thanks to both answerers here. – Cole Commented Oct 7, 2012 at 18:30
Add a ment  | 

2 Answers 2

Reset to default 12

It looks like you have an array with a nested array, so you're only calling join on the top array which only has one element (the child array) and therefore just echoes that array with default behavior and nothing to delimit.

There is only one item in the jsss array so there is no use for the separator. I think what you want is jsss[0].join('&');

发布评论

评论列表(0)

  1. 暂无评论