+ 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
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.
+ 2
course will contain ["HTML", "CSS" "JS", "C++"]
then course[2] its the third element then its "JS"
+ 1
got it thank yu dude