I know I can get the last item in an array using:
_.nth(arr, -1)
or arr[arr.length - 1]
or arr.slice().pop()
and many, many more...
How about getting just the index?
My array looks like this:
[
{ icon: 'twitter', url: '#'},
{ icon: 'facebook', url: '#'},
{ icon: 'instagram', url: '#'},
],
How would I get the index of the last item? I am trying to find the simplest, one line solution, without using map
or looping.
Note: ReactJS solutions are also accepted if any.