How to Concatenate, Join and Sort Array in JavaScript?

In the previous post, I have already described about “How to Loop Through JavaScript Array”. Along with accessing an element of an array using looping statements, you can also concatenate, join and sort an array in JavaScript. In this post you will learn about How to Concatenate, Join and Sort Array in JavaScript.

How to Join Two Arrays using Concat()

Using concat() method, you can join to arrays array1 and array2 as below.

<script>
var array1=new Array(3);
array1[0]=”Saab”
array1[1]=”Volvo”
array1[2]=”BMW”

var array2=new Array(3);
array2[0]=”Yamaha”
array2[1]=”Honda”
array2[2]=”Bajaj”

var array3=array1.concat(array2);

for(i=0; i<array3.length;i++)
{
document.write(array3[i]+”<br/>”)
}
</script>

Preview:

var array1=new Array(3);
array1[0]=”Saab”
array1[1]=”Volvo”
array1[2]=”BMW”

var array2=new Array(3);
array2[0]=”Yamaha”
array2[1]=”Honda”
array2[2]=”Bajaj”

var array3=array1.concat(array2);

for(i=0; i

About shuseel

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 5 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Leave a Comment

Your email address will not be published. Required fields are marked *