A smarter approach to improve efficiency and reduce time complexity (n^3) while retrieving all variables.
getrewarddata
represents an objectd1, d2, d3...
are individual variables
//Object contains various rewards for different months
const getrewarddata = [{
month: 6,
year: 2021,
reward: 6,
},
{
month: 1,
year: 2021,
reward: 6,
},
{
month: 3,
year: 2021,
reward: 6,
},
];
//Split the array based on specific month variable
let d3 = getrewarddata.filter((data) => data.month === 3);
let d2 = getrewarddata.filter((data) => data.month === 2);
let d1 = getrewarddata.filter((data) => data.month === 1);
console.log(d2);
console.log(d3);