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 badges3 Answers
Reset to default 4You 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