I am having array of objects with date key,i want to filter out the objects which has current week,how can i achieve this which returns me the current week of objects.i tried using filter but first i need to format date key i guess.
const notificationItems = [
{
id: 1,
date: '2021-02-10T05:04:59.525589Z',
name: 'Glenn',
},
{
id: 2,
date: '2021-02-10T05:04:59.525589Z',
name: 'Root',
},
{
id: 3,
date: '2021-01-08T05:04:59.525589Z',
name: 'Smith',
},
{
id: 4,
date: '2019-02-03T05:04:59.525589Z',
name: 'Ryan',
},
{
id: 5,
date: '2019-01-03T05:04:59.525589Z',
name: 'Bob',
}
]
Maybe you can consider using of moment.js library https://github.com/moment/moment
notificationItems.filter(
(notification) =>
moment(notification.date).week() === moment().week() &&
moment(notification.date).year() === moment().year()
);
then by this code you will get only the notifications on this week
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With