admin 管理员组文章数量: 1086019
I'm attempting to integrate with a legacy system which depends on a value being sent via a GET request as a tab delimited string. I have my data in an array, but am having an issue trying to join()
it in the correct manner.
Here's is what I've attempted, none of which works;
var myArray = ["a", "b", "c"]
myArray.join(\t);
myArray.join(/\t/);
myArray.join('\t');
myArray.join('\\t');
myArray.join(' '); // tab character
Edit
It appears the actual issue appears that joining by \t
does indeed work, however when it is URL encoded the tab is not being turned into %09
as it should be, but is instead removed.
Desired URL encoded var:
"?tags=a%09b%09c"
Actual output:
"?tags=abc"
Does anyone know how to solve this?
I'm attempting to integrate with a legacy system which depends on a value being sent via a GET request as a tab delimited string. I have my data in an array, but am having an issue trying to join()
it in the correct manner.
Here's is what I've attempted, none of which works;
var myArray = ["a", "b", "c"]
myArray.join(\t);
myArray.join(/\t/);
myArray.join('\t');
myArray.join('\\t');
myArray.join(' '); // tab character
Edit
It appears the actual issue appears that joining by \t
does indeed work, however when it is URL encoded the tab is not being turned into %09
as it should be, but is instead removed.
Desired URL encoded var:
"?tags=a%09b%09c"
Actual output:
"?tags=abc"
Does anyone know how to solve this?
Share Improve this question edited Nov 30, 2018 at 7:57 Rory McCrossan asked Apr 19, 2013 at 13:21 Rory McCrossanRory McCrossan 338k41 gold badges320 silver badges351 bronze badges 1-
How do you show the output? maybe you just need
 
? And what's wrong with:myArray.join(' ');
? – gdoron Commented Apr 19, 2013 at 13:23
3 Answers
Reset to default 6This one works on my chrome console :
var myArray = ["a", "b", "c"];
console.log(myArray.join('\t'));
See on this jsfiddle.
This one is working too :
myArray.join(' '); // tab character
Browser : Chrome 26.0.1410.65 (os x)
Edit :
var myArray = ["a", "b", "c"];
var string = myArray.join('\t');
var url = encodeURIComponent(string);
console.log(url); //output : a%09b%09c
http://jsfiddle/mGZdk/2/
Your problem is that you aren't assigning it to a new variable. Join() does not modify the original variable. Try this:
var myArray = ["a", "b", "c"]
var array_string = myArray.join('\t');
alert(array_string);
\t
should work...
var arr = [1, 2, 3];
var str = arr.join("\t");
However, how are you displaying your output? If you are trying to display the content on a normal HTML page, the tabs will appear like spaces. If you put the contents in special elements like <pre>
, they should appear normally.
I know it's a nasty solution, but you can use multiple
instead...
var arr = [1, 2, 3];
var str = arr.join(" "); // s-sorry ;__;
本文标签: javascriptJoin() an array by tabStack Overflow
版权声明:本文标题:javascript - Join() an array by tab? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744062807a2527036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论