+ 1

var c1 = ["HTML", "CSS"]; var c2 = ["JS", "C++"]; var courses = c1.concat(c2); document.write(courses[2]);

need bit by bit explanation for the code.. dono why it only prints JS

21st Jun 2018, 8:51 AM
Soniya Ramesh
Soniya Ramesh - avatar
3 Respuestas
+ 5
Soniya Ramesh the .concat() method combines the two arrays into a new single array. Therefore, in your example, c2 is combined with c1. Creating a new array that contains all those elements. courses = ["HTML", "CSS", "JS", "C++"]; courses[2] refers to the third element in the new array which is "JS". courses[0] = "HTML" courses[1] = "CSS" courses[2] = "JS" courses[3] = "C++" I hope my explanation helps.
21st Jun 2018, 9:03 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
course will contain ["HTML", "CSS" "JS", "C++"] then course[2] its the third element then its "JS"
21st Jun 2018, 9:04 AM
KrOW
KrOW - avatar
+ 1
got it thank yu dude
21st Jun 2018, 9:04 AM
Soniya Ramesh
Soniya Ramesh - avatar