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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:31:37+00:00 2026-05-30T01:31:37+00:00

I have an array of objects called objarray . Each object looks like this:

  • 0

I have an array of objects called objarray. Each object looks like this:

var object = {
    age: "45"
    coords: "-37.807997 144.705784"
    date: Sun Jul 28 2002 00:00:00 GMT+1000 (EST)
}

(date is a Date object)

I need to push each object into a new array based on the date. I want the end result to look like this:

var dateGroups = [[object, object, object],[object, object], [object, object, object]];

Each array within dateGroups contains objects with the same date.

Is this possible to do with arrays? Previously I generated a new object which contained all the objarray objects grouped by date (dates generated from the data):

var alldates = {
  "1991" : [object, object, object],
  "1992" : [object, object],
  //etc...
}

The above seems like a weird solution in practice though, I only need to be able to access the objects by year: i.e. dateGroups[0] = array of objects from the first year

How would I get the data into something like the dateGroups array? Is there a better way to store this type of data?

  • 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-05-30T01:31:38+00:00Added an answer on May 30, 2026 at 1:31 am

    Consider using the Underscore.js groupBy function, followed by sortBy.

    groupBy will produce a structure like alldates, if you call it like so:

    var alldates = _.groupBy(objarray, function(obj) {
        return obj.date.getFullYear();
    });
    

    sortBy can be used to simply sort by key, like this:

    var dateGroups = _.sortBy(alldates, function(v, k) { return k; });
    

    You can also combine the two like this:

    var dateGroups = _.chain(objarray)
                      .groupBy(function(obj) { return obj.date.getFullYear(); })
                      .sortBy(function(v, k) { return k; })
                      .value();
    

    Depending on your use case, I can see reasons for using an array of arrays, or an object map of arrays. If you’re looking up on index, definitely use the later.

    • 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 objects. Each object has a property called name. I
I have code similar to this filtering entries in an Array of Objects: var
I have a JavaScript array of objects like this: box[0] = {...} box[1] =
I have an NSMutableArray of custom objects called Clip. Each clip Object has some
I have an array of objects in MATLAB and I've called their constructors in
I have an array of FileReference objects which have several listeners attached to each
I have an array of CLLocation objects and I'd like to be able to
I have an array of custom objects. MyCustomArr[]. I want to convert this to
I have an array of JavaScript objects: var objs = [ { first_nom: 'Laszlo',
I have an array of ActiveRecord objects, each one which has its own respective

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.