0

I have a form and I need to create a multidimensional array based on a DOM element that a user can generate more than once with a click of a button.

var dimention = $(".stations").length;

This is how get the number of <div class="stations">...</div>" elements on the page and based on this number I need to create an array.

I currently defined var stations = [[],[],[],[],[]]; 5 manually but I need to do this dynamically, in case the user wants to create more than 5. Thanks.

0

1 Answer 1

1

In this case, you could just create an array, and make it the length necessary, then make each section in the array, an array within itself. Something like:

var stations = new Array(dimension);
// Create an array of size dimension.
for (var i = 0; i < stations.length; i++) {
    // At each point in the array, assign a new array object.
    stations[i] = new Array(20);
}
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.