JavaScript : Define an empty array

スポンサーリンク

var emptyArray = [];

var newEmptyArray = new Array();

These two are the same, and []; is simpler way. There is no need to use the later one unless you need to define the length of the array.

var anotherEmptyArray = new Array(100);

This defines anotherEmptyArray having 100 items with all slots containing undefined.

コメント

タイトルとURLをコピーしました