+ 2

How can we add more than Two (2) Arrays to form a new array?

Array Construction

3rd Feb 2018, 9:08 AM
Joseph Mike
Joseph Mike - avatar
3 Answers
+ 3
Give an example of what you mean by add do you mean [1,2]+[3,4]=[4,6] or [1,2]+[3,4]=[1,2,3,4]
3rd Feb 2018, 9:49 AM
Louis
Louis - avatar
0
//consider the given two variables of courses (c1 and c1), thus; var c1 = ["HTML", "CSS"]; var c2 = ["JS", "C++"]; //if we want to combine the above arrays,we must apply the Javascript's concat.. hence; var courses = c1.concat(c2); document.write(courses); //will return the output of 4 element: HTML,CSS,JS,C++ (as a single Array). //My Question is,.. as from the above example we used 'concat' to add two courses. therefore, how can we add more than Two courses like the Below Arrays to form new Array? var courses = new Array() var c1 = ["Mathematics","Physics"]; var c2 = ["Electrical", "Mechanics"]; var c3 = ["Computer", "Telecom"]; var c4 = ["Engineering","Technology"];
3rd Feb 2018, 10:26 AM
Joseph Mike
Joseph Mike - avatar