javascript array join – How to Join Array Elements in javascript?

0
()

javascript array join method is used to join the elements of an array into a string. Write a simple JavaScript program to join all elements of the following array into a string.

javascript array join

The join() method does not change the original array. also The concat() method is used to merge two or more arrays.The js array join() method combines all the elements of an array into a string and return a new string.

Syntax of array join

array.join(separator);

Java Script Array join()

const websites = ["Pakainfo", "Infinityknow", "W3diy", "Google"];
let text = websites.join();

Example

const websites = ["Pakainfo", "Infinityknow", "W3diy", "Google"];
let text = websites.join(" and ");

Don’t Miss : Array To String Javascript

Read Also:  jquery validation for mobile number

JavaScript: Join all elements of an array into a string

index.html

<html>
   <head>
      <title>Java Script Array join Method - www.pakainfo.com</title>
   </head>
   
   <body>   
      <script type = "text/javascript">
         var websites = new Array("Pakainfo","Infinityknow","W3diy");
         
         var result = websites.join();
         document.write("result : " + result ); 
         
         var result = websites.join(", ");
         document.write("<br />result : " + result ); 
         
         var result = websites.join(" + ");
         document.write("<br />result : " + result ); 
      </script>      
   </body>
</html>

JavaScript Array join() method

Using the js Array join() method to replace all occurrences of a string

const result = 'Welcome To Pakainfo.com Free Download source code';
const url = result.split(' ')
    .join('-')
    .toLowerCase();

console.log(url);

Download

I hope you get an idea about javascript array join.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  jQuery Background Change

How useful was this post?

Click on a star to rate it!

Free Live Chat for Any Issue