1

I currently have a function that is called multiple times because it recursivly decends through my program. Every time that function is called I am trying to create a new array. As my program decends it runs another function that adds items into that new array. Once all those items are added into that array I am then trying to push that array into another array that stores all my different arrays containg different elements.

For Example:

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
    }
}

Is this possible?

2
  • 2
    how about if we start learning JS before asking this type of questions? w3schools.com/js/js_arrays.asp Commented Apr 16, 2016 at 4:46
  • The code you've given is too vague. I can't see any recursion happening. JavaScript can appear deceptively simple at first glance, but I think it would really help you to read through a good introduction, for example, github.com/getify/You-Dont-Know-JS. Commented Apr 16, 2016 at 4:55

1 Answer 1

1
// Create array
let myArray = ["1"];
// Add Item
myArray.push("2");

// Add Items of another array
let otherArray= ["3", "4"];
myArray.push([...otherArray]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.