My object:
const data = {
"rows": [
{
"code": "ct101",
"username": "admin",
"subscriptionExpiresOn": "2019-11-27T09:35:38.916Z",
},
{
"code": "bt101",
"username": "admin",
"subscriptionExpiresOn": "2016-11-27T08:20:57.297Z",
},
]
}
There is a key called 'subscriptionExpiresOn' in my object inside rows array,
I want to check condition, If subscriptionExpiresOn is < new Date(). I need output like this:
// Changing the value into 'Expired'
const data = {
"rows": [
{
"code": "ct101",
"username": "admin",
"subscriptionExpiresOn": "2019-11-27T09:35:38.916Z",
},
{
"code": "bt101",
"username": "admin",
"subscriptionExpiresOn": "Expired",
},
]
}
Here what i tried using map method:
const now = new Date();
data.rows.map((index) => {
if (index.subscriptionExpiresOn < now) {
return {
subscriptionExpiresOn: 'Expired',
};
} else {
return data;
}
});
But its not working.