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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:38:58+00:00 2026-06-09T07:38:58+00:00

I have two variables in my javascript. A message function : var message A

  • 0

I have two variables in my javascript.
A message function : var message
A timestamp function : var date(It is of type timestamp)..

Now I have an array which stores messages according to there timestamp. Something like

    var input = []; //dynamic array to store both message and date
    var date = new Date(update.data.history[i].timestamp * 1000); //Getting from Json object
    var date_input = date.toLocaleTimeString();
    var message = update.data.history[i].message;
        for (i to length)
    {
        input.push({ key: date_input, value: message });     //Key refers to date, and value to message
    }
   input.sort(sort_by(key,true,parseInt));

My function sort_by

var sort_by = function(field, reverse, primer){

   var key = function (x) {return primer ? primer(x[field]) : x[field]};

   return function (a,b) {
       var A = key(a), B = key(b);
       return (A < B ? -1 : (A > B ? 1 : 0)) * [1, -1][+!!reverse];                  
   }
}

Now, I tried debugging with firebug and noticed my sorting function is not working. I am using timestamp as key but still no luck. Is there anyway I can sort it according to timestamp and then display it. I tried other sorting solutions on SO, but I guess there is another way to sort when there is datatype like timestamp?

  • 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-09T07:39:00+00:00Added an answer on June 9, 2026 at 7:39 am

    The sorting function works perfectly. When I was debugging it with firebug, I saw on the console that even though date-input was “6-29-07 am”, it was only taking 6 as the “key”, therefore every entry on that particular day was assigned the same key. Therefore, sorting was not able to give the desired output. Therefore, I avoided new date() function in second line, directly took the timestamp as key, sorted accordingly, and then convert it into date-format. Silly error, but took some time.

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

Sidebar

Related Questions

I have two variables like : <script language=javascript type=text/javascript> var count = 1; calc_my_project_
I have a simple javascript function that takes two variables. I need to pass
I have a javascript which takes two variables i.e two lists one is a
I have these two date time variables in javascript: first_date = Date.parse('05/21/2012 0:00:00 ');
I have two variables. weekStartDate and startDate. they both hold essentially the same timestamp:
I have two string variables which are both file paths. The code that worked
I have got 2 javascript variables: var list1 = john doe|bill williams|poll bregg|michael jordan;
In JavaScript, I want to write a function that determines if the two variables
I have two variables, 'a' and 'b' in my JavaScript, and i want to
I have a javascript function that walks a tree recursively. It has two flag

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.