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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:15:41+00:00 2026-06-17T15:15:41+00:00

So I am working out of a previous question I asked here , in

  • 0

So I am working out of a previous question I asked here, in which I talked about making a history timeline from a JSON file using AngularJS. Essentially, the JSON file contains a bunch of HISTORY EVENTS object, each of them containing an ID called “theDate” to indicate the date at which these unique events took place. I want to sort all of the events into their specific DECADES for navigation purposes later in the view and using CSS.

I’m struggling with creating a multidimensional array whose structure should be something like this (this should be the MASTER array):

[[all of 1960s events],[all of 1970s events], [all of 1980s events]...]

…In which each of those specific arrays within the MASTER array contains event objects for that specific decade. (For example, for the 1960s array, the events should contain the years [ 1961, 1963, 1969,etc.].

Working with AngularJS, I have my working code here:

        var events = $scope.events;

    function decadeSort(){

        var year;
        var arrayOfYears = [];


        for(var i = 0; i<events.length; i++){

            var date = new Date(events[i].theDate);
            year = date.getFullYear();

            var yearToString = year.toString();
            var yearToDecade = yearToString.substring(0,3).concat("0");
            arrayOfYears.push(yearToDecade);


        }
        console.log(arrayOfYears);
    };

    decadeSort();

The arrayOfYears array prints out all the YEAR of the 267 event objects according to their respective DECADE like this:

["1960","1960","1970","1970","1970","1980","1980","1990","1990","2000","2000"..]

With some of the string objects in THAT array repeat, I was hoping to create new arrays WITHIN that array based on which objects are the same strings. I don’t know how to write this loop, so any insight and help would be greatly appreciate.

Thank you so much!

  • 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-17T15:15:42+00:00Added an answer on June 17, 2026 at 3:15 pm

    Using the sample-event you posted, the following is a simply way to group-by decade:

    var grouped = {};
    
    events.forEach(function (event) {
      var decade = Math.floor((new Date(event.theDate)).getFullYear() / 10) * 10;
      if (typeof grouped[decade] === 'undefined') {
        grouped[decade] = [];
      }
    
      grouped[decade].push(event);
    });
    
    console.log(grouped);
    

    It’s using forEach which you might need to change, if you’re targeting a browser that does not support it.

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

Sidebar

Related Questions

In a previous question, I asked about various ORM libraries. It turns out Kohana
This is a follow-on from a previous question ( here ), but I'm working
Following on from my previous question I have been working on getting my object
This is a follow-up question from here . The code is working great, it
As per my previous question , I have a working animation which fades in
I figured out the solution for my previous question which landed me into new
Working off my previous question I'm trying to figure out how to achieve what
I can't figure out why the next page/previous page buttons stop working after a
Hey all, I'm working on cleaning up my code from previous semesters. Previously I
I'm working under a domain, and im making an app that changes ip from

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.