Notsodoshi
Notsodoshi

Reputation: 1

Unable to run the code effectively If condition is not functioning effectively

I have an array of month & year and i have a start month and year. What i want to do is to filter out the month and year which matched to the start month and year. But for some reason my if loop is not filtering month & year

Code Snippet:

for (let a of data) {      
if (start_date_data[0].month && start_date_data[0].year !== a.month && a.year) {} 

where am i going wrong ? please help

Image for reference data [1]: https://i.sstatic.net/VAFwb.png

Upvotes: 0

Views: 22

Answers (1)

Aakash Garg
Aakash Garg

Reputation: 10969

It should be :-

for (let a of data) {      
if (start_date_data[0].month !== a.month && start_date_data[0].year !== a.year) {} 

Upvotes: 2

Related Questions