I have a question that I believe is straightforward, but I've seen conflicting answers on.
Let's say I have the following data structure:
const data = [
...,
{
someKey: [
...,
{
someDeepKey: [
...,
'two'
],
}
]
}
]
So accessing the first index of all of the following would look like this:
data[0].someKey[0].someDeepKey[0]
But if I wanted to find the LAST index of all of these, I haven't found a clean method. I have seen some people recommend extending the Array prototype itself, which I feel is a bad idea.
The only other "clean" solution I can think of is to chain down variables to make it semi readable.
let someKey = data[data.length - 1].someKey
let someDeepKey = someKey[someKey.length - 1].someDeepKey
let someDeepKeyValue = someDeepKey[someDeepKey.length - 1]
Can anybody suggest a cleaner way to do this? I believe Python supports something neat such as:
data[-1].someKey[-1].someDeepKey[-1]
and I was wondering if there is anything similar in JS.