1

So, how would you remove all objects from an array.. My current code is:

            var array = [""];
            function add() {
                var input = document.getElementById("enterInput").value;
                array.push(input);

                var arrayOut = document.getElementById("output").innerHTML = array;
            }

            function clearit() {
                var length = array.length;
                array.splice(0, length, length);
                array.push("");
            }

Thanks, Noah.. (and yes, I have checked the console and no errors are returned.)

1
  • Don't pass a third argument to splice.
    – Bergi
    Jul 18, 2015 at 21:20

3 Answers 3

3

Just use

function clearit() {
    array = []; //or array = [""];
}
1
1

maybe just redo the array

array = [""]
1

Can also use:

    array.length = 0;

Not the answer you're looking for? Browse other questions tagged or ask your own question.