0

I am kinda new to javascript and struggling a bit to do this. I have a list of Objects like this on client side (javascript)

[{id:1,amount_spent:15,date:06/16/2017},
{id:1,amount_spent:10,date:06/15/2017},
{id:1,amount_spent:10,date:06/01/2017},
{id:1,amount_spent:15,date:05/22/2017},
{id:1,amount_spent:10,date:05/24/2017},
{id:1,amount_spent:15,date:04/18/2017},
{id:1,amount_spent:10,date:04/19/2017},
{id:1,amount_spent:15,date:04/19/2016}]

now, I want to group them on weekly basis some how and display it in html as

note: Week start day is always Sunday and Week End day is always Saturday

week start: 06/11/2017 || week end: 06/17/2017

total amount spent = 25

week start: 05/28/2017 || week end: 05/03/2017

total amount spent = 10

week start: 05/21/2017 || week end: 05/27/2017

total amount spent = 25

week start: 04/16/2017 || week end: 04/22/2017

total amount spent = 25

week start: 04/17/2016 || week end: 04/23/2016

total amount spent = 15

and also I want to display it for monthly basis and yearly basis

example for yearly basis grouping on the sample json data:

year 2017

total amount spent = 85

year 2016

total amount spent = 15

Thanks in advance

Community
  • 1
  • 1
  • Welcome to Stackoverflow. You have to be very careful when asking questions. Make sure the question is fully researched, include things you've tried, desired result, current result and all relevant code. Your question should also include an actual question. :P – KidBilly Jun 16 '17 at 13:26
  • this can get you started in the right direction: https://stackoverflow.com/questions/5210376/how-to-get-first-and-last-day-of-the-week-in-javascript – Icculus018 Jun 16 '17 at 13:34
  • thanks that helped a lot – user1759751 Jun 18 '17 at 00:16

0 Answers0