+ 1

Is there a difference between these methods of declaring an array ?

What's the difference between declaring an array like this: var courses = new Array(); courses[0] = "HTML"; courses[1] = "CSS"; courses[2] = "JS"; and declaring it like this : var courses = ["HTML", "CSS", "JS"];

28th Jan 2020, 8:16 PM
Marina Khamis
Marina Khamis  - avatar
2 Answers
+ 5
The solution of your doubt is here. https://www.w3schools.com/js/js_arrays.asp If you have more than 100, 200, 300 items in Array they you can use second type of declaration.
28th Jan 2020, 8:21 PM
A͢J
A͢J - avatar
+ 1
Second is simple, readable, and executes faster. I think the first form is more of a novelty-use type thing than practical, but I honestly find the first form a bit easier to understand. At least in terms of having the element index right there instead of having to constantly remind myself an array starts at 0.
29th Jan 2020, 12:08 AM
c0dezer019
c0dezer019 - avatar