how to create arrays in a function


#1

am working on a function where the input of n, produces an output of n arrays .
eg arr(1) >>> newArray1=[];
arr(2) >>>> newArray1=[]; newArray2=[]
arr(3) >>>> newArray1=[];newArray2=[];newArray3=[];

function arr(n){

}

this is what am coming up with, a main array where i pusher other arrays, i can call them by index not by name

var mainArry=[];
var aYY=[];
for (var i=1; i<=n;i++){
var aYY = [i];
mainArry.push(aYY );
}
}


#2

You’re looking for something like this?

function arr(n) {
	for (var i = 1; i <= n; i++) this["newArray" + i] = [i]
}
arr(3)
newArray2.push("foo")
alert(newArray2) //2, foo