How Can I Use Array Join Method 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 array join method.

How Can I Use Array Join Method In JavaScript With Example

 

The join() method returns the array as a string.

The elements will be separated by a specified separator. The default separator is comma (,).

Note: this method will not change the original array.


Syntax and Usage

array.join(separator)
 

Parameter Values

separator -> Optional. The separator to be used. If omitted, the elements are separated with a comma

Let's starts

Example(1)

1.Create array
var flowers = ["Lily", "Rose", "Lotus", "Jasmine"];
 

2.how to use  join() method

var x = document.getElementById("demo");
x.innerHTML = flowers.join();


Example(2)

function joinfunction() {
    var flowers = ["Lily", "Rose", "Lotus", "Jasmine"];
    var x = document.getElementById("demo");
    x.innerHTML = flowers.join('-');
}


Complete code for Array Join Method In JavaScript

 
<!DOCTYPE html>
<html>
<head>
    <title>How Can I Use Array Join Method In JavaScript With Example</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>
<style>
    h3{
        color:red;
    }
</style>
<body>
<div class="container">
    <br>
    <br>
    <div class="text-center">
        <h1>Use Array Join Method In JavaScript </h1>
    </div>
    <br>
    <div class="well">
        <button class="btn btn-primary" onclick="joinfunction()">Click it</button>
        <h1 id="demo"></h1>
    </div>
    <br>
</div>
</body>
</html>
<script>

    function joinfunction() {
        var flowers = ["Lily", "Rose", "Lotus", "Jasmine"];
        var x = document.getElementById("demo");
        x.innerHTML = flowers.join();
    }
</script>

Related Post