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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:26:08+00:00 2026-05-23T04:26:08+00:00

I have a json object r : [ { id : 3443, name :

  • 0

I have a json object r:

[ 
  {
    "id"     : "3443",
    "name"   : "Joe",
    "date1"  : "254",
    "date4"  : "261"
  },
  { "id"     : "50942",
    "name"   : "John",
    "date2"  : "192",
    "date4"  : "195"
  },
  { "id"     : "2524",
    "name"   : "Mary",
    "date1"  : "153",
    "date4"  : "163"
  }
]

and I wish to have a Javascript For loop to go through the dateX values.
I know that X is between 1 and a Max value.

But following code does not work:

for (j=1; j<=Max; j=j+1) {
  datestring = 'date' + j;
  if (isset(r[i].datestring)) value[j] = r[i].datestring;
  else value[j] = null; 
}

Forgot to explain that I defined the isset function as:

function isset(variable) {
  return typeof(variable) != "undefined" && variable !== null;
} 
  • 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-23T04:26:09+00:00Added an answer on May 23, 2026 at 4:26 am

    First iterate through the array of objects with an ordinary for loop. Then iterate through the properties of each object with for (var p in obj) and check the value of p. Something like:

    for (var i = 0; i < arr.length; i++) {
        var obj = arr[i];
    
        for (var p in obj) {
            if (/^date\d+$/.test(p)) {
                var value = obj[p];
                // p is a dateX property name and value is the value
            }
        }
    }
    

    It’s counter-intuitive and inefficient to loop through all possible property values to check their existence. Instead, loop through the actual properties and test their names against your pattern.

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

Sidebar

Related Questions

Suppose I have a json object that looks like: { id: 1, name: john
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have a JSON object returned from server. It looks like this : {1:{id:1,name:autos},
I have this JSON object {stores:{ 1:{ name:Publix, address:1fbdfhbdhsdhsrh, long:-84.012502, lat:33.878952}, 2:{ name:Publix, address:fgsregerge,
So I have a json object which has a structure like so: { John
for example i have this json object: {h:[username,hair_color,height],d:[[ali,brown,1.2],[mar c,blue,1.4],[joe,brown,1.7],[zehua,black,1.8]]} how do i convert this
I'm working on JavaScript and I have this JSON object: var obj ={name :
I have a json object collection of geo locations that I build in the
Hi I have a JSON object that is a 2-dimentional array and I need
I have created a json object from ruby with cobravsmongoose, however the attributes have

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.