@jgCarroll/

arrayConstructor

JavaScript

A common interview question

fork
loading
main.js
1
2
3
4
5
6
7
8
9
var arr1 = [];
var arr2 = new Array(50); 
var arr3 = new Array(1, 2, "three", 4, "five"); 
var arr4 = new Array([1, 2, 3, 4, 5]);
 
console.log('arr1: ', arr1); // logs an empty array
console.log('arr2: ', arr2); // array constructor function with the parameter 50. Logs an array with 50 empty items
console.log('arr3: ', arr3); // creates an array
console.log('arr4: ', arr4); // creates an array with one element in it - an array
Native Browser JavaScript