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 7868365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:58:36+00:00 2026-06-03T00:58:36+00:00

Im trying to add an array to a webpage. I have tried a few

  • 0

Im trying to add an array to a webpage. I have tried a few different pieces of code show below but none of them work. I would like the output to be similar to a list like:

text1

text2

text3
…

The code I have used so far is:

var i;
var test = new Array();
test[0] = "text1";
test[1] = "text2";
test[2] = "text3";

// first attempt
$('#here').html(test.join(' '));

// second attempt
$(document).ready(function() {
    var testList="";
    for (i=0;i<test.length; i++) {
        testList+=  test[i]  + '<br />';
    }
    $('#here').html('testList');
    songList="";
}); 

I am quite new to javaScript so I am not sure if I have just made a small mistake or if Im doing this in the wrong way. Also, above is a copy of all the code in my javaScript file and some places online are saying I need to import something? Im not sure!
Thanks

  • 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-03T00:58:37+00:00Added an answer on June 3, 2026 at 12:58 am

    What you have works if you remove the single quotes from testList. However, if you would like an actual unordered list you can do this. (here’s a jsFiddle)

    var test = new Array();
    test[0] = "text1";
    test[1] = "text2";
    test[2] = "text3";
    
    // first attempt
    $('#here').html(test.join(' '));
    
    // second attempt
    $(document).ready(function() {
        var testList=$("<ul></ul>");
        for (var i=0;i<test.length; i++) {
            $(testList).append($("<li></li>").text(test[i]));
        }
        $('#here').html(testList);
        songList="";
    }); ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add values from array to DB, have tried many variuos examples
Im trying to add objects to an array by using push. I have a
I'm trying to add values to an array via foreach but it only returns
I am trying to add id of an element to an array. But I
I am trying add value to a mutlidimensional array but I am slightly confused
I have two array with string values, and one dictionary, im trying to add
I have been trying to add variables from a dropdown into an array using
I have an array of JPanel s and I'm trying to add a mouseadapter
I have a function which grows an array when trying to add an element
I am trying a add data to an array using a while loop but

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.