Which of the following is the correct way to declare an array in JavaScript?

  • var myArray = [];
  • array myArray = [];
  • myArray = new Array();
  • myArray = {}
The correct way to declare an array in JavaScript is by using square brackets []. So, var myArray = []; is the correct syntax. The other options are either not valid or used in different programming languages.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *