配列を宣言するとき、オブジェクトリテラル(var arr = [];)とかArrayクラスで初期化(var arr = new Array();)などの方法がある。 (一般的にオブジェクトリテラルを使うのが推奨されてるが) そして、初期化直後の配列は何も入っていない空の状態で生成される。 コーディングする上で、どうしてもすべての要素をゼロで初期化したかったのだが、なんだかうまくいかない。 ということで、配列をゼロで初期化する方法を調べてみた。 配列をゼロで初期化する方法 Array.prototype.map() を使う方法 配列の中身に何か(nullでもundefinedでもOK)が入っている場合は、以下のとおり。 var arr1 = [null, null, null]; arr1 = arr1.map(function () {return 0 }); console.log('a