我目前有一个被多次调用的函数,因为它在我的程序中递归下降。每次调用该函数时,我都会尝试创建一个新数组。当我的程序下降时,它运行另一个函数,将项目添加到新数组中。一旦所有这些项目都添加到该数组中,我就会尝试将该数组推送到另一个数组中,该数组存储包含不同元素的所有不同数组。
例如:
var staticarray = [];
function createarray(){
if(test == true){
//creates new array
}
additems();
//pushes array to staticarray
}
function additems(){
if(anothertest == true){
//adds items into new array
}
}
这可能吗?
最佳答案
// Create array
let myArray = ["1"];
// Add Item
myArray.push("2");
// Add Items of another array
let otherArray= ["3", "4"];
myArray.push([...otherArray]);
关于javascript - 你能在Javascript中动态创建一个数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36660185/