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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:11:22+00:00 2026-06-11T23:11:22+00:00

I have an javascript array that is hard coded into my javascript file: var

  • 0

I have an javascript array that is hard coded into my javascript file:

var avatar_layers = new Array('background', 'body', 'hair', 'shirt', 'arms', 'legs', 'feet', 'weapon')

As it is hardcoded, it is difficult to use it between different HTML files.

I would like to change it so the javascript will look for all the h3 tags that have a class of title on the page and use the content of these tags to create the array.

How can I do this?

After reading around, I have found that I should use the following

document.getElementsByTagName(“h3.title”)[0];

This will get all the h3.titles. However, I am not sure how to output the collected data as array.

I would really appreciate any pointers. Thanks!

Update: I can’t use Jquery, it has to be regular java script

You can see my code here: http://jsfiddle.net/zk5Hn/2/

  • 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-11T23:11:23+00:00Added an answer on June 11, 2026 at 11:11 pm
    ​var array = [];
    
    (function(){
        var elements = document.getElementsByTagName("h3");
        for (var i = 0; i < elements.length; i++) {
            array.push(elements[i].innerText);
        }
    })();
    
    ​alert(array);​
    

    try that.

    http://jsfiddle.net/Jsckt/

    alternatively you could use jquery:

    $(function(){
        var array = [];
    
        $("h3.title").each(function() {
            array.push(this.innerText);
        });
    
        alert(array);
    }​;​
    

    http://jsfiddle.net/Jsckt/2/

    5 years later edit:

    1. one should avoid using innerText theese days for performance and expectational reasons
    2. you can explode DOM node lists to arrays now

    there you go with a up2date solution for 2018 onwards:

    const headings = [...document.querySelectorAll("h3.title")].map(node => node.textContent);
    alert(headings);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this array, that I want to parse into javascript. $offerText[] = (
I have a JavaScript array that can be built using this code var Test
I am currently trying to pass an array that I have created in Javascript
I have a Knockout observable array that I wish to edit from within Javascript
I have an array in javascript that I need to join and send through
I have a variable length array of strings declared in javascript that contains Dungeons
I have a javascript array: var exclude = [Santorum,Obama,Romney,Gingrich]; I have html links: <a
1) I have this Javascript array: lang=new Array(); lang[sq]=Albanian; lang[ar]=Arabic; lang[en]=English; lang[ro]=Romanian; lang[ru]=Russian; 2)
Hey. I have this javascript file that I'm getting off the web and it
I have a very simple JavaScript array that may or may not contain duplicates.

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.