I apologize if this question is too simple, I am just getting started in JavaScript. I have the following problem: A function is returning an array similar to:
[
"Wed Feb 24 11:39:01 CST 2021",
"Thu Mar 21 18:35:30 CDT 2019",
"Tue Feb 26 15:23:50 CST 2019"
]
My challenge is to grab just the year from each of those elements within the array (so I need to grab 2021, 2019, and 2019).
I was thinking in my head to use .split by using space as the delimitator and then using length-1 to get the last element. But my implementation keeps throwing errors.
I tried:
var fromDate = $dateList[*].dates
var fromDateSplit = fromDate.split(' ');
var fromYear = fromDateSplit[fromDateSplit.length - 1]
Please let me know what I am doing wrong. Getting ready to pull hair out.
Thank you in advance for looking at this!