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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:07:35+00:00 2026-06-09T04:07:35+00:00

I have an array sorted in ascending order in java script which contains dates

  • 0

I have an array sorted in ascending order in java script which contains dates in milliseconds.

// Sample data; This may grow upto 1k or 2k
var dates = [1333391400000,1335292200000,1335810600000,1336329000000,1336933800000,1337020200000,
1337193000000,1337538600000,1337625000000,1337797800000,1338316200000,1338921000000,
1339093800000,1339439400000,1340303400000,1341772200000,1342463400000,1343068200000];

I don’t have start and end index. I have values. I need to get all dates between 2 dates (Min and Max) from the java script array. I am getting this array from Java through JSON.

Here is the method to get dates between min and max:

function getDatesBetweenRange(min,max){
    var subArray = [];
    var value, jCntr=0;
    for(var iCntr=0;iCntr<dates.length;iCntr++){
         value = dates[iCntr];
         if(value>max)
             break;
         if(value >=min && value <=max){
             subArray[jCntr++]= value;
         }
    }
    return subArray;
}

As array is in ascending sorted order; I am breaking loop if I get max value than the provided max value in the argument.

Is there any other efficient way to get values from Java Script array ?

  • 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-09T04:07:37+00:00Added an answer on June 9, 2026 at 4:07 am

    Here’s a semi binary filter method that seems more efficient (at least in my browsers – Chrome, Firefox, IE9)

    function filterBinary(arr,min,max){
     var len   = arr.length
        ,up    = -1
        ,down  = len
        ,rrange= []
        ,mid   = Math.floor(len/2) 
     ;
     while (up++<mid && down-->mid){
        if (arr[up]>=max || arr[down]<=min){break;}
        if (arr[up]>=min){
          rrange.push(arr[up]);
        }
        if (arr[down]<=max){
          rrange.push(arr[down]);
        }
     }
     return rrange;   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of values which is almost, but not quite sorted, with
I have a method that sorts an array of numbers in ascending order and
I have to sort this array in descening order with the key likecount. How
I have an array(sorted on an attribute called node_id) of ruby objects which basically
I have a set of data and ask Matlab to sort in ascending order
hi i have an array of objects which need to be sorted (alphabet on
Okay, this one is pretty complicated... lets say I have an array called $data
I have a sorted array of doubles (latitudes actually) that relatively uniformally spread out
1-)For sorted array I have used Binary Search. We know that the worst case
I have a array with users sorted by score. I only want to output

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.