to get the last key of an object this is what i must write, but i don't understand why we need minus -1
Object.keys(myObject)[Object.keys(myObject).length - 1]
I have tried to remove minus 1 and it is undefined in the console.
to get the last key of an object this is what i must write, but i don't understand why we need minus -1
Object.keys(myObject)[Object.keys(myObject).length - 1]
I have tried to remove minus 1 and it is undefined in the console.
When searching in array, you use index. The first item in array has index 0, the next item 1, the next item 2...
However, someArray.length returns how many items are in array.
So length starts from 1 (if array isn't empty), but index starts from 0. So you need to deduct 1 :).