After Passing Javascript Array To Servlet, How Do I Edit?

- 1 answer

I have javascript array that I've passed to java. This is an array of user input data. I want this list of user input data to be editable, so first will the javascript array be editable with this code for the array?

form.addEventListener('submit', collectData, false);

function collectData(e) {
    var userSites = [];
    var cache = document.getElementById('cache');
    var z = 0;
    while (z < max_fields) {
        var data = inputs[z].val();

    cache.value = userSites;

I want the user to be able to go back and edit the list later if they so choose and then for the array to update when this happens. I don't know much about javascript, but I know a lot about java. So in java I know that an array list would be better for this, but is that something that works in javascript?



Arrays in JavaScript are very modifiable, unlike Java. JavaScript arrays are not a fixed length, and items can be added and removed without any issues.

Slightly unrelated, but something I noticed in your example; JavaScript arrays are 0-indexed, like Java, but in your while loop, you are incrementing z before it ever gets a chance to parse the 0-th element. Did you mean to do that?