How To Convert Arrays to Strings In JavaScript With Example

admin_img Posted By Bajarangi soft , Posted On 25-09-2020

JavaScript is a dynamic programming language. Java Script can combine with any other language ( Its used as a part of web pages), whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities. In The JavaScript we have so many in built method so today we are going to discuss how to convert arrays to strings.

How To Convert Arrays to Strings In JavaScript With Example

The JavaScript method toString() converts an array to a string of (comma separated) array values.

Syntax

array.toString()

Lets Starts

1.Create Array

var flowers = ["Lily", "Rose", "Lotus", "Jasmine"];
 

2.Use in Built toString() Function

document.getElementById("demo").innerHTML = flowers.toString();


Complete code of Convert Arrays to Strings In Java Script
 
<!DOCTYPE html>
<html>
<head>
    <title> Convert Arrays to Strings In JavaScript</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <br>
    <br>
    <div class="text-center">
        <h1> Convert Arrays to Strings In JavaScript</h1>
    </div>
    <br>
    <div class="well">
        <h1 id="demo"></h1>
    </div>
    <br>
</div>
</body>
</html>
<script>

    var flowers = ["Lily", "Rose", "Lotus", "Jasmine"];
    document.getElementById("demo").innerHTML = flowers.toString();
</script>

Related Post