Is there a way to destruct the last item in an array if I don't know it's length in advance?
I have:
let response = {
data: [
{ name: 'item1', level: 1 },
{ name: 'item2', level: 10 },
{ name: 'item3', level: 11 }
]
};
And I would like to get name
and level
of the last item in the array.
I know I can get an item with a specific index, for instance:
const {data: [,, {name, level}]} = response
But as the data
array has a various length, it doesn't suit.