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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:04:17+00:00 2026-06-02T19:04:17+00:00

I am looking to create a simple array using a time stamp for the

  • 0

I am looking to create a simple array using a time stamp for the index so that I can access the values by timestamp without iterating through the array, however I am struggling!

I need to be able to set 2 values for each row.

For example:

var myarray = [];
var test1 = 'hello'
var test2 = 'world'

myarray[timestamp] = [test1, test2];

So for a given timestamp e.g. 12345678, how could I access the value of test2?

Appreciate any thoughts and advice.

Regards, Ben.

  • 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-02T19:04:18+00:00Added an answer on June 2, 2026 at 7:04 pm

    If you use an array that way, you’ll end up with an array containing a large amount of undefined values:

    var myarr = [];
    myarr[1000] = 'hello';
    console.log(myarr.length); //=> 1001 
    console.log(myarr[0]); //=> undefined
    console.log(myarr[999]); //=> undefined
    

    So, you may want to use an object for that and use some kind of sorting. For example

    var myobj = {}, timestamp = new Date().getTime();
    myobj[timestamp] =   ['hello','world'];
    myobj[timestamp+1] = 'how are we today?';
    
    function retrieveSorted(obj){
      var keys = Object.keys(obj).sort(), key, ret = [];
      while(key = keys.shift()){
        ret.push(obj[key]);
      }
      return ret;
    }
    
    var sorted = retrieveSorted(myobj); 
       //=> [["hello", "world"], "how are we today?"]
    myobj[timestamp][1]; //=> world
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to create a simple web service that when polled returns a unique
I'm looking to create a simple iOS app that displays the current water level
I am looking to create a simple array wrapper with a few helper methods,
I'm looking to create a simple brute-force password-cracker which will hash an input from
I'm looking for as simple way to create an identity set. I just want
I'm looking for a simple JavaScript library or framework to create interactive 2D animations
I looking to create a custom calender with Zend Framework, I am hoping that
Im looking to create a control that would look like comic baloon. In WPF
I am looking to create a site that will allow users to create groups
im looking forward to create an upload module where user can browse, click open

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.