Help with arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TechGuy86
    New Member
    • Jun 2012
    • 1

    Help with arrays

    I am tryin to put to display the elements of an array, with each element of the array on a seperate line.
    Code:
    <script type="text/javascript">
            var names = prompt("Enter Names:","Enter names here.");
            var names_array = [names.split(" ")];
            var array_length = names_array.length;
            var i = 0;
            var array_display = names_array.join("<br>");
            for (i;i<array_length;i++)
            {
                document.write("You entered the following names:"+"<br>"+array_display)
            }
        </script>
    Please, anyone, what am I doing wrong here? It is probably the simplest thing, but for the life of me, I can't figure out what works.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    line #3. you create an array with exactly 1 element (which itself is an array, btw)

    Comment

    Working...