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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:42:57+00:00 2026-06-03T05:42:57+00:00

Lets say I have three divs in my HTML <div> <h2>This is div 1</h2>

  • 0

Lets say I have three divs in my HTML

<div>
    <h2>This is div 1</h2>
</div>
<div>
    <h2>This is div 2</h2>
</div>
<div>
    <h2>This is div 3</h2>
</div>

Also, I have a JavaScript array made of three nested arrays:

var array = [ 
    [ "<p>Bla bla</p>", "<p>Other stuff</p>"], 
    [ "<p>Another paragraph</p>"], 
    [ "<p>Yet another</p>", "<p>yes</p>", "<p>yes</p>" ] 
    ];

I am sure that this array will always have three members, just like the number of divs.

What I want to do is append the content of each of the nested arrays of the main array to the div with the corresponding number.

Something like:

for ( var i = 0; i < array.length; i++ ) {
    $('div').eq( i ).append( array[i] );
}

The above code doesn’t work but I think my intention is clear.

You can find a working example here => http://jsfiddle.net/G8BsK/

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-03T05:42:59+00:00Added an answer on June 3, 2026 at 5:42 am

    Change this…

    .append( array[i] );
    

    to this…

    .append( array[i].join('') );
    

    Although I would highly recommend taking the DOM selection out of the loop, and caching it.

    var divs = $('div');
    for ( var i = 0; i < array.length; i++ ) {
        divs.eq( i ).append( array[i].join('') );
    }
    

    …or just do this…

    $('div').append(function(i) {
        return array[i].join('');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
Lets say I have this kind of set of images: <div class=image><img src=image1.jpg alt=
So let's say I have a block of nested divs: <div class='nested'> <div class='nested'>
Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I
Lets say I have one row with three columns - some buttons on left
Lets say there are two pages with two different html elements which have the
Let's say I have the following HTML: <div> text1 <div> t1 </div> text2 <div>
lets say i have a tree of the following structure: <div>node level1 <div>node level2
Lets say I have three models/tables: operating_systems , words , and programming_languages : #
I have three tables, we'll call them table1, table2, and table3. Lets say each

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.