Pinkie Pinkie - 1 year ago 140
Javascript Question

JavaScript arrays braces vs brackets

What is the difference between each of the following array definitions.

var myArray = [];
var myArray = {};
var myArray = new Array();

Answer Source

The first and third are equivalent and create a new array. The second creates a new empty object, not an array.

var myArray = []; //create a new array
var myArray = {}; //creates **a new empty object**
var myArray = new Array(); //create a new array
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download