Converting number to string or array to string

<script type="text/javascript">
var scripts = new Array();
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
document.write(scripts.toString());

</script>
The output of the above script is here
PHP,ASP,JavaScript,HTML
Javascript toString() can connect all elements of an array and return as a string. This function toString() uses commas as separators while adding all the elements.

If you want to specify your own delimiter other than commas then you can use array join function

toString with number

We can convert number to string by using toString().
<script>
var my_var = 13;
document.write(my_var.toString()); // output is 13 
document.write(my_var.toString(2)); // output is 1101
document.write(my_var.toString(8)); // output is 15
document.write(my_var.toString(16)); // output is d 
</script>
The input parameter is base value to convert number. By default the base value is taken as 10 in first case.
Converting String to Number Creating Array
Array Reference How to display elements of an Array

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer