Skip to content
Advertisement

javascript create empty array of a given size

in javascript how would I create an empty array of a given size

Psuedo code:

X = 3;
createarray(myarray, X, "");

output:

   myarray = ["","",""]

Advertisement

Answer

var arr = new Array(5);
console.log(arr.length) // 5
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement