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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:02:54+00:00 2026-05-22T15:02:54+00:00

I have a json array that has multiple missing numbers and is out of

  • 0

I have a json array that has multiple missing numbers and is out of sequence. What is the best way to find which numbers are missing?

My First thought was to iterate through and construct a new temporary array in order (so if the first key is 50, it goes to arr[50]) and then find out which do not have a key. Unfortunately this seems extremely inefficient.

Update:
Here’s a bit of my json:

"groups": [
    {
      "group_id": "1",
      "group_name": "AABYODAADAAAW6KAAA",
    },
    {
      "group_id": "5",
      "group_name": "AABYODAADAAAW6KAAB",
    },
    {
      "group_id": "2",
      "group_name": "AABYODAADAAAW6KAAC",
    },
    {
      "group_id": "3",
      "group_name": "AABYODAADAAAW6KAAAD",
    },
    {
      "group_id": "6",
      "group_name": "AABYODAADAAAW6KAAAE",
    }
]

and I’m sorting group_id, but the array length is over 2,000.

  • 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-05-22T15:02:55+00:00Added an answer on May 22, 2026 at 3:02 pm

    Assuming this is a JS object you’re talking about (and not a JS Array or a JSON Array or a JSON Object), you’ll have to loop twice:

    var max;
    for (var key in obj) if (obj.hasOwnProperty(key) && (!max || key>max)) max = key;
    for (var i=0;i<=max;++i) if (obj[i]==undefined){
      console.log("Missing: "+i);
    }
    

    Edit: Based on your updated sample, it appears that you have an array of objects whose keys are strings that represent integers, and you want to figure out keys might be missing. Here’s code that would do that:

    var groups = myObj.groups;
    var groupNames = [];
    for (var i=0,len=groups.length;i<len;++i){
      groupNames[groups[i].group_id] = groups[i].group_name;
    }
    for (i=0,len=groupNames.length;i<len;++i){
      var name = groupNames[i];
      if (name==undefined){
        console.log("Oops, no name for group_id: "+i);
      }else{
        // Do what you want
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON result that has an array of messages: { messages: [
Hi I have a JSON object that is a 2-dimentional array and I need
I have a program written in C that has to input and output JSON
I have a jquery auto complete script that takes a JSON array and displays
I have a json array in my Particles controller that looks like this after
I have a json object retrieved from server in my $(document).ready(...); that has an
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have one JSON that is coming in a string format. I need to
I have a JSON result that contains numerous records. I'd like to show the
i've got a SQL query which returns multiple rows, and i have : $data

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.