Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8334691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:26:11+00:00 2026-06-09T03:26:11+00:00

I have an array.js file and an index.html . My array.js file looks like

  • 0

I have an array.js file and an index.html.

My array.js file looks like this:

function go(){
    var array = new Array();
    array[0] = "Red";
    array[1] = "Blue";
    array[3] = "Green";
    for (var i=0; i < array.length; i++){
        document.write("<li>" + array[i] + "<br />");
    }
}

My index.html file looks like this:

<html>
    <head>
        <script type="text/javascript" src="array.js"></script>
    </head>
    <body>
        <input type="button" onclick="go()" value="Display JS Array"/>
        <script>
            go();
        </script>
    </body>
</html>

When I click the Display JS Array button on the HTML page, nothing happens.
I want the array elements to be displayed after I click the button.
It should look like:

  • Red
  • Blue
  • Green
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:26:15+00:00Added an answer on June 9, 2026 at 3:26 am

    replace this document.write("<li>" + array[i] + "<br />"); with document.write("<li>" + array[i] + "</li>");

    and in your HTML file, remove

    <script>
      go();
    </script>
    

    because already you calling go(); function on onclick. and in your array, array[2] will give undefined.

    try this its working for me :

        <html>
        <head>
            <script type="text/javascript">
                function go(){
                    var array = new Array();
                    array[0] = "Red";
                    array[1] = "Blue";
                    array[2] = "Green";
                    li = document.getElementById("list");
                    li_arr = "";
                    for (var i=0; i < array.length; i++){
                       li_arr += "<li>" + array[i] + "</li>";
                    }
                   li.innerHTML = li_arr;
                }
            </script>
        </head>
        <body>
            <input type="button" onclick="go()" value="Display JS Array"/>
            <ul id="list"></ul>
        </body>
    </html>
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
I am new In PHP.I have js file look like var sites = [
I have template for example index.html.php where I use php assetic loader like this
OK i have 2 files one is index.php and the other is file.html now
I have an array of file names which I want to download. The array
I have a array stored in a PHP file in which I am storing
In my main file I have an array of character strings, char names[320][30], and
In a build.rake file I have an array holding names of JavaScript files: JS_FROM_INDEX=`./bin/extract_files
I have dynamic array filled with bytes, which are read from .raw file with
I have a byte array filled from a file uploaded. But, in another part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.