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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:14:28+00:00 2026-06-15T23:14:28+00:00

Possible Duplicate: Find length (size) of an array in jquery I have a json

  • 0

Possible Duplicate:
Find length (size) of an array in jquery

I have a json object returned from a php file as follows:-

{"food":[
    {
        "name"       :"Belgian Waffles",
        "price"      :"$5.95",
        "description":"two of our famous Belgian Waffles with plenty of real maple syrup",
        "calories"   :"650"
    },
    {
        "name"       :"Strawberry Belgian Waffles",
        "price"      :"$7.95",
        "description":"light Belgian waffles covered with strawberries and whipped cream",
        "calories"   :"900"
    },
    {
        "name"       :"Berry-Berry Belgian Waffles",
        "price"      :"$8.95",
        "description":"light Belgian waffles covered with an assortment of fresh berries and whipped cream",
        "calories"   :"900"
    }
]}

This is essentially returning three food elements from the object. How can I get a count of the total number of elements being returned if the json data is dynamic and not known using jquery?

  • 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-15T23:14:30+00:00Added an answer on June 15, 2026 at 11:14 pm

    Assuming you’ve parsed the JSON (or jQuery has done it for you, which it will if you use its Ajax functions) and you have the resulting object in a variable, just do this:

    var data = /* your parsed JSON here */
    var numberOfElements = data.food.length;
    

    (Note: There’s no such thing as a JSON object: before you parse JSON it’s a string; after you parse it it’s an object.)

    EDIT: In a comment you said you wouldn’t know that the property is called food – if you do know that there will be exactly one property and that property will be an array you can do this:

    var data = /* your object */
    var propName;
    var numberOfElements;
    for (propName in data);
    numberOfElements = propName ? data[propName].length : 0;
    

    If you don’t know that there will be exactly one property then your requirement is too vague: if there might be multiple properties which one would you want to check the length of?

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

Sidebar

Related Questions

Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
Possible Duplicate: How to find a duplicate of length 5 in a single array.
Possible Duplicate: jquery reading nested json I would really like to have a hard
Possible Duplicate: how to access parent window object using jquery? I have the following
Possible Duplicate: Array length undefined I have the following array but whenever I try
Possible Duplicate: indexOf method in an object array? I have a javascript array which
Possible Duplicate: Find url from string with php I found this code: but 2
Possible Duplicate: Find text string using jQuery? How do you find a text string
Possible Duplicate: Find and Replace more than 1 word? I want to use jQuery
Possible Duplicate: Easiest way to find duplicate values in a JavaScript array Javascript array

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.