I am using Javascript. I have a set of data I need to remove the object based on element value. Here I have attached my code. In my code I have month element. I need to remove the object when month is 1. How to do this?
var Data=[
{ "State": "PA", "DispenseMonth": "1/1/2017" },
{ "State": "MS", "DispenseMonth": "1/1/2017" },
{ "State": "CT", "DispenseMonth": "1/1/2017" },
{ "State": "TX", "DispenseMonth": "2/1/2017"},
{ "State": "DE", "DispenseMonth": "2/1/2017"},
{ "State": "TN", "DispenseMonth": "2/1/2017" },
{ "State": "FL", "DispenseMonth": "3/1/2017" },
{ "State": "SD", "DispenseMonth": "4/1/2017" },
{ "State": "GA", "DispenseMonth": "5/1/2017"},
{ "State": "SC", "DispenseMonth": "6/1/2017"},
{ "State": "IA", "DispenseMonth": "7/1/2017" },
{ "State": "RI", "DispenseMonth": "8/1/2017" },
{ "State": "ID", "DispenseMonth": "9/1/2017"}
]
Data.forEach(item => {
return item.Month = item.DispenseMonth.split('/')[0];
});
console.log(Data);
Code I tried:
for(i = 0; i < MainStateData.length; i++) {
var bjMonth = MainStateData[i].Month;
if (bjMonth == 1) {
delete MainStateData[bjMonth];
MainStateData.splice([i]);
delete MainStateData[i];
}
}
forloop andsplicewhen condition satisfies.m/d/yyyy?