Knowledge Walls
John Peter
Pune, Maharashtra, India
How to join arrays in Javascript with Example
3142 Views
Hints 
concat method is a prototype of Array object in Javascript. Using concat method can join an array with an array. In below example names1 and name2 array is getting added then returns that merged data to names3 object.

Notes
names1 and names2 object are not changed after done deployment.
names3 only getting changed. so that it returns the concated data not changing names1 and names2 arrays.
Join arrays in Javascript
var names1 = new Array();
    names1.push("Siva");
    names1.push("Kumar");

var names2 = new Array();
    names2.push("Lakshanya");
    names2.push("Vidhyaa");

var names3 = names1.concat(names2);

document.write(names1+"<br />");
document.write(names2+"<br />");
document.write(names3+"<br />");
Output 
Siva,Kumar
Lakshanya,Vidhyaa
Siva,Kumar,Lakshanya,Vidhyaa

[Click here to see Demo]
Best Lessons of "Good Javascript Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details