In my current dataset, I have an array of objects with 12 indexes, each containing 2 values. The keys 'months' and 'year' are included in each index. 'Months' is a sub-array, while 'year' is currently stored as a string but could easily be converted to an integer.
My goal is to sort this array of objects based on the value of the 'year' key
Currently, the data looks like this:
0: {months: {…}, year: "2017"}
1: {months: {…}, year: "2019"}
2: {months: {…}, year: "2018"}
3: {months: {…}, year: "2011"}
4: {months: {…}, year: "2010"}
5: {months: {…}, year: "2012"}
6: {months: {…}, year: "2013"}
7: {months: {…}, year: "2015"}
8: {months: {…}, year: "2014"}
9: {months: {…}, year: "2016"}
I am attempting to sort this list from lowest to highest years. I initially tried using map, but couldn't get it to work correctly. Any advice on how to achieve this would be greatly appreciated. Thank you.