I've got a dates array and I wanted to create a function that returns all the dates from 2014 or 2015 depending on what the user clicks
i tried using substring(), although that gives me an array of the 2014 dates, it also returns 2 undefined's which I dont want. How would I return an array of only 2014 dates?
const datefunc = () => {
const date = ['2014-4-4', '2014-5-4', '2015-4-4', '2015-3-4']
const dates = date.map((d) => {
if (d.substring(0, 4) === '2014') {
return d;
}
})
console.log(dates)
}
datefunc()