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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:24:42+00:00 2026-06-06T05:24:42+00:00

I am working on a function that accepts a JSON object as a parameter.

  • 0

I am working on a function that accepts a JSON object as a parameter. Each property of the object passed in will be an array. I need to determine the length of each of these arrays.

What I won’t know in advance are: the names of the properties, or how many properties there are.

How can I determine the length of each array? Again, I can’t refer to any of the properties/keys explicitly because I won’t know their names ahead of time. How do I reference each unknown property as an array?

Thank you in advance,
-RS

  • 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-06T05:24:44+00:00Added an answer on June 6, 2026 at 5:24 am

    You can iterate over the object using a for...in loop to access each property.

    for (var key in myObject) {
      // Check to make sure the property is not part of the `Object` prototype (eg. toString)
      if (myObject.hasOwnProperty(key)) {
        console.log(key, myObject[key].length);
      }
    }
    

    In the above example, we iterate over the properties of the object myObject and we log out their length values (assuming they are all arrays).

    If by “JSON object” you mean that it is a string of JSON, you can first parse myObject into a true object by using myObject = JSON.parse(myObject) (which works in modern browsers) or myObject = eval("(" + myOjbect + ")") which is considered unsafe (but works in all browsers). After parsing, you may use the above technique to fine array lengths.

    Note: Since you updated the post to specify that the object is JSON, you may not need the hasOwnProperty check, but it is safer to always use this test.

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

Sidebar

Related Questions

I am working on a function that will essentially see which of two ints
I have a function which accepts a parameter named IV. Is there anyway that
Is piping parameter into line is working only for functions that accept one parameter?
I'm working on a function that handles events from a number of buttons and
I'm working with a PHP function that takes a string and converts all of
I search for the function that run programm by path, and working of main
I'm asking this because I'm working with a recursive function that generates a large
Hey, I was working with a PHP function that takes multiple arguments and formats
I am working with datetime objects in python. I have a function that takes
In the application I'm working on, there is a function that connects with a

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.