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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:45:17+00:00 2026-06-01T19:45:17+00:00

Okay, so I did search a bit before posting… no luck (or maybe I’m

  • 0

Okay, so I did search a bit before posting… no luck (or maybe I’m just stupid).

I have this array I call “myArray” and I push objects onto it to populate some variables:

myArray.push({
    time        : (y.moveTime - y.startTime),
    pos         : y.move,
    last        : myArray[y.recents.length-1].time
});

My issue is why does firebug complain about the “last” variable: “Uncaught TypeError: Cannot read property ‘time’ of undefined“. If I do

last        : myArray[y.recents.length-1]

everything is fine.

An observation I don’t understand:
The array is empty when I have the “.time” reference, but if I remove it, the array is full.

What am I missing here? I don’t get it 🙁

Thanks for any pointers.

  • 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-01T19:45:19+00:00Added an answer on June 1, 2026 at 7:45 pm

    The error means that the evaluated value of

    myArray[y.recents.length-1]
    

    is not an object that has a time property. This likely occurs when you perform the first push because the array does not yet have any elements.

    If you want to hide the error and just assign the last property to undefined in this case, you can just add a fallback value:

    last: (myArray[y.recents.length - 1] || {}).time 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I have done a bit of searching online and found this thread, but
Okay, before you guys go nuts -- this is just a small site, temporary
Okay, I think I'm just making a stupid mistake here, but I want to
Okay, this thing is driving me insane, I have tried every way, I have
I did followed this blog here and here . And i have the following
Okay, so I've had this code that used to work just fine. I recently
Okay, this is a bit abstract, but here goes: I'm creating a website and
Okay, this will be a bit hard to explain, but I'll try my best.
Okay, I did my homework and search SO, and indeed I found similar questions
Okay, so I did all the research for this issue but none of the

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.