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]
|