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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:01:23+00:00 2026-06-12T14:01:23+00:00

I have an array of items in Javascript similar to the following: var data

  • 0

I have an array of items in Javascript similar to the following:

var data =
[
{"id":"338b79f07dfe8b3877b3aa41a5bb8a58","date":"2000-10-05T13:21:30Z","value":  {"country":"United States"}},
{"id":"338b79f07dfe8b3877b3aa41a5bb983e","date":"2000-02-05T13:21:30Z","value":{"country":"Norway"}},
{"id":"338b79f07dfe8b3877b3aa41a5ddfefe","date":"2000-12-05T13:21:30Z","value":{"country":"Hungary"}},
{"id":"338b79f07dfe8b3877b3aa41a5fe29d7","date":"2000-05-05T13:21:30Z","value":{"country":"United States"}},
{"id":"b6ed02fb38d6506d7371c419751e8a14","date":"2000-05-05T18:15:30Z","value":{"country":"Germany"}},
{"id":"b6ed02fb38d6506d7371c419753e20b6","date":"2000-12-05T18:15:30Z","value":{"country":"Hungary"}},
{"id":"b6ed02fb38d6506d7371c419755f34ad","date":"2000-06-05T18:15:30Z","value":{"country":"United States"}},
{"id":"b6ed02fb38d6506d7371c419755f3e17","date":"2000-04-05T22:15:30Z","value":{"country":"Germany"}},
{"id":"338b79f07dfe8b3877b3aa41a506082f","date":"2000-07-05T22:15:30Z","value":{"country":"United Kingdom"}},
{"id":"9366afb036bf8b63c9f45379bbe29509","date":"2000-11-05T22:15:30Z","value":{"country":"United Kingdom"}}
];

I need to query (reduce) the array by the date. Either greater than or less than a pre-determined date eg. current date.

I was thinking of using Underscores reduce method to do this. Can anybody provide an example of how I could do this?

Edit: I trying something like this:

var itemsByDate = _(items).reduce(function(memo, item) {
memo[item.date] = memo[item.date] || [];
memo[item.date].push(item);
return memo;
}, {});

console.log((JSON.stringify(itemsByDate["2000-11-05T22:15:30Z"])));​

But this looks for an exact match and will probably not deal with the dates properly because they are strings.

Regards,

Carlskii

  • 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-12T14:01:24+00:00Added an answer on June 12, 2026 at 2:01 pm

    If you want to filter the set, you can do this:

    var reduced = data.filter(function(obj) {
        var date = +(new Date(obj.date));
        return date < someDate || date > someOtherDate
    });
    

    If you wanted to reduce it to a pair of sets, you can do this:

    var now = Date.now();
    
    var reduced = data.reduce(function(ret, obj) {
        var date = +(new Date(obj.date));
        if (date < now)
            ret.before.push(obj);
        else
            ret.onOrAfter.push(obj);
        return ret;
    }, {before:[], onOrAfter:[]});
    
    • 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 items as follows in Javascript: var users = Array();
I have the following JavaScript array: var President = new Array(); President[0]=Thomas Jefferson; President[1]=Thomas
I have an array which contains sets of three similar named items; however, sometimes
I have some simple Javascript looping through an array of items (Tridion User Groups)
Hi I have a javascript array object rapresenting the amount of items sold in
I have an array of ~50 items and in javascript it goes through this
i have a three arrays in javascript var array1 = new Array (1,2,3,4,5); var
I have an javascript array, which looks like: var styles = new Array(); styles[0]
I have the following array setup, i,e: var myArray = new Array(); Using this
If have an array of Javascript IDs var myArray = ['2', '1', '3']; Now,

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.