+ 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"];
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.
+ 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.