You don't need to slice the array (which uses additional memory, as it creates a new array) to do that.
What you are describing is a loop that starts at index = 96 until it reaches 0, decreasing index one by one.
So you just need to change let i = keyToValue2.length[96] - 1 to let i = 96.
Here's an example using an array with 32 values and logging them backwards, starting at index 16. Just used these values because StackOverflow snippets limit the number of log entries:
// This creates a new array with 32 numbers (0 to 31, both included):
const array = new Array(32).fill(null).map((_, i) => `Element at index ${ i }.`);
// We start iterating at index 16 and go backwards until 0 (both included):
for (let i = 16; i >= 0; --i) {
console.log(array[i])
}
If you want to make sure the index 96 actually exists in your array, then use let i = Math.min(96, keyToValue2.length - 1:
// This creates a new array with 32 numbers (0 to 31, both included):
const array = new Array(32).fill(null).map((_, i) => `Element at index ${ i }.`);
// We start iterating at index 31 (as this array doesn't have 64 elements, it has only 32)
// and go backwards until 0 (both included):
for (let i = Math.min(64, array.length - 1); i >= 0; --i) {
console.log(array[i])
}
let i = 96 - 1instead oflet i = keyToValue2.length[96] - 1.