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

jquery - How to convert arraylist to string in Javascript? - Stack Overflow

programmeradmin5浏览0评论

How to convert arraylist to string in Javascript?

I just want to convert arraylist to string in Javascript. I have this code.

var digitStack = [];
digitStack.push(1);
digitStack.push(2);
digitStack.push(3);

and I want to make "123". Any good ideas do you have?

How to convert arraylist to string in Javascript?

I just want to convert arraylist to string in Javascript. I have this code.

var digitStack = [];
digitStack.push(1);
digitStack.push(2);
digitStack.push(3);

and I want to make "123". Any good ideas do you have?

Share Improve this question asked Sep 4, 2015 at 3:58 Yuri BaeYuri Bae 631 silver badge7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You can use the Array.join() with an empty string as the separator

var digitStack = [];
digitStack.push(1);
digitStack.push(2);
digitStack.push(3);
var string = digitStack.join('');

snippet.log(string)
<!-- Provides the `snippet` object, see http://meta.stackexchange./a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>

Just use Array.join() :

var digitStack = [];
digitStack.push(1);
digitStack.push(2);
digitStack.push(3);

var digitStr = digitStack.join('');

console.log(digitStr); // gives you a string.

User Arrayname.join();

var digitStack = [];
digitStack.push(1);
digitStack.push(2);
digitStack.push(3);

var digitStr = digitStack.join(''); //predefined function

document.write(digitStr); // just to verify the string, it has to be removed later
发布评论

评论列表(0)

  1. 暂无评论