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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:03:24+00:00 2026-06-04T14:03:24+00:00

Sorry I’m new here and my code will probably not be properly displayed… how

  • 0

Sorry I’m new here and my code will probably not be properly displayed…

how would I iterate through document to find arrays with .each()?

I was thinking something like this:

//-----START OF CODE----\\
var a = new Array("a0", "a1", "a3");
var b = new Array("b0", "b1", "b3");
var i = 0;

function CountArrays()
{    
    $('Array').each(function(){

        i++;            
    });
    alert("There are " + i + " arrays in this document!");
}

CountArrays();
//-----END OF CODE----\\

But $(‘Array’) doesn’t seem like the way to go, because I don’t receive an alert!

Thanks for your help! 🙂

  • 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-04T14:03:25+00:00Added an answer on June 4, 2026 at 2:03 pm

    No, no. This does not work. Please get familiar with the jQuery Library.

    $('foo');
    

    The $() function excepts a CSS Selector as a Parameter and returns an jQuery object, you can’t put just variables into it. Your Javascripts and your HTML are two different things.

    If you want to iterate over arrays in your code use the following:

    var a = ["Hello","World"];
    for (var i = 0; i < a.length; i++) {
        alert(a[i]);
    }
    

    There are plenty of ways to iterate over an array, see this for a reference.

    Second: As mentioned using alert() to debug is not a good idea, especially when looping something.
    Use console.log('string', variable) instead when you are using Chrome or Firefox. It’s writing your variables straight into the console and it also logs complete objects which is not possible with alert().

    Update after comment: It’s not possible to iterate over all existing arrays in your javascript. That’s because you can’t list all existing variables. One problem is, that your creating a new scope with every new function.

    The variables inside the function don’t know about the ones outside. So for example this is a valid piece of code:

    var a = 5;
    
    function foo() {
        var a = 6;
    
        return a;
    }
    
    console.log(a); // prints "5"
    console.log(foo()); // prints "6"
    

    Both variables are called a, but they contain different data.
    For further info see this answer: https://stackoverflow.com/a/2051693/735226

    And just by the way: Why do you even want to know how many arrays there are in your scripts? And since objects can contain arrays like this

    var objWithArray = {
        foo:5,
        bar:[3, 4, 5, 6, 7] // objWithArray.bar would be an array
    };
    

    there is no way to get all arrays. Javascript is a typeless and mutable language.

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

Sidebar

Related Questions

Sorry for a long question and not a very descriptive title, but my problem
Sorry I could not find this. $('div#loader').slideDown(fast).delay(1.5); Does not word as expected, I want
sorry, I am pretty new in WPF and I think it's pretty easy, but
Sorry if this is a noob question, but All my code is error-free and
Sorry to bother you all here but I am still trying to understand more
Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry the title is not very descriptive but it is a tricky problem to
Sorry for real stupid question. But it does not work either way. <html> <head>
Sorry if this is a noob question :( . Piece of C code. int
Sorry. I don't know a good title for this, but please look here: http://joshblog.net/projects/logic-gate-simulator/Logicly.html

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.