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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:39:21+00:00 2026-06-05T10:39:21+00:00

You can see a working example here: http://jsfiddle.net/bwhitney/ZDHp4/1/ I am trying to create an

  • 0

You can see a working example here:

http://jsfiddle.net/bwhitney/ZDHp4/1/

I am trying to create an array of objects in javascript. When I attempt to access the objects I am getting “undefined” output. Here is some sample code:

var dates = [];

var beginDate1 = new Date("01 / 01 / 01");
var endDate1 = new Date("02 / 02 / 02");
var beginDate2 = new Date("03 / 03 / 03");
var endDate2 = new Date("04 / 04 / 04");

// this outputs the correct dates
alert("before: " + beginDate1 + "--" + endDate1);
alert("before: " + beginDate2 + "--" + endDate2);

dates.push({
    "beginDate": beginDate1,
    "endDate": endDate1
}, {
    "beginDate": beginDate2,
    "endDate": endDate2
});

var date;
for (date in dates) {
    // this outputs "date: undefined--undefined"
    // why would that be?
    alert("after: " + date.beginDate + "--" + date.endDate);
}
  • 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-05T10:39:22+00:00Added an answer on June 5, 2026 at 10:39 am

    The for ... in loop in JavaScript gives you the keys in the object, not the values.

    You really should use a numeric index however:

    for (var date = 0; date < dates.length; ++date) {
      alert("date " + date + " is: " + dates[date]);
    }
    

    Iterating over keys with for ... in will not pick up only the numerically-indexed array elements; it operates on arrays as if they are plain ordinary objects. Other properties will be picked up too, plus you’re not even guaranteed it’ll go in ascending numeric order!

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

Sidebar

Related Questions

I'm working on a jquery carousel. You can see the example here: http://jsfiddle.net/6fwbS/2/ Click
Consider the following example (also available here: http://jsfiddle.net/hq8Fg/1/ ). It works fine in IE9,
As you can see on http://jsfiddle.net/FrelCee/5zcv3/4/ , i want to animate those 3 divs
Working on a carousel lightbox tooltip demo and as far I can see in
I'm working on a Java version of MS Paint. You can see what it
From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended
I can see it looks like an alias for an unsigned int pointer, right?
I can see where svn:keywords like Id, LastChangedDate and Author are used and replaced
I can see how to change the fonts and colors in the IDE. Is
I can see that GD library is for images. But I can't see differences

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.