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

  • Home
  • SEARCH
  • 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 8426065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:26:47+00:00 2026-06-10T04:26:47+00:00

I have a working version of a function to loop through a single array

  • 0

I have a working version of a function to loop through a single array in a JSON object, e.g.

[{
    "Name": "John",
    "Surname": "Johnson"
}, {
    "Name": "Peter",
    "Surname": "Johnson"
}]

sample function:

function FindName(NameToFind, data1) {

    objData = JSON.parse(data1);

    for (var i = 0; i < objData.length; i++) {

        var Name = objData[i].Name;

        if (Name == NameToFind) {
            alert("found!");
        }
    }
}

Now I need to change this function to allow for either single OR multiple arrays e.g.

{
    "Table1": [{
        "Name": "John",
        "Surname": "Johnson"
    }, {
        "Name": "Peter",
        "Surname": "Johnson"
    }],

    "Table2": [{
            "Name": "Sarah",
            "Surname": "Parker"
        },
        {
            "Name": "Jonah",
            "Surname": "Hill"
        }
    ]
}

Is there a way to determine whether the object has 1 array (like in first example) or more than one arrays (like in 2nd example), and any advice/guidance on how to extend the function to be able to loop through all the items whether it has 1 array or multiple arrays?

  • 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-10T04:26:49+00:00Added an answer on June 10, 2026 at 4:26 am

    Your first object is an array, the second one isn’t.

    You can test if your argument is an array, or even just test

    if (objData[0]) // that's an array
    

    EDIT :
    if you want to iterate over all properties of a (just json decoded) object, when it’s not an array, you can do this :

    for (var key in objData) {
        var value = objData[key];
        // now use the key and the value
        // for example key = "Table1"
        // and value = [{"Name":"John","Surname":"Johnson"}, ... ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working version of tooltip (jQuery Tools - http://flowplayer.org/tools/demos/tooltip/index.html ) , jQuery(document).ready(function()
Here is a simplified version of what I have (not working): prog.h: ... const
I use TortoiseSVN for version control. In a working cooy I have been working
I have just begun working on a project which uses Mercurial as a version
I have Git (version 1.7.2.5) bash compeletion working on my Debian squeeze (6.0). Git
I have installed the latest version of netbeans and its working.. I have opened
I'm working with an older version of Rails and ActiveRecord that does not have
Currently, I have this version of the autocomplete control working when returning XML from
My Xcode's snapshot feature isn't working well. (version 4.2.1) I have used the snapshot
I currently have a somewhat working version of what I need to be done,

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.