JSFiddle - React, Tailwind, and code Playground
HTML
Look in the console.
JavaScript
const isArrayIndex = name => {
if (typeof name !== "symbol" && /^\d+$/.test(name)) {
const n = +name;
return n >= 0 && n < 4294967295; // 2**32 - 1
}
return false;
};
const reversedView = array => new Proxy(array, {
get(target, prop, receiver) {
if (isArrayIndex(prop)) {
prop = target.length - 1 - prop;
}
return Reflect.get(target, prop, receiver);
}
});
const a = [1, 2, 3, 4];
for (const value of reversedView(a)) {
console.log(value);
}
const objects = [
{id: 1, type: 1},
{id: 2, type: 2},
{id: 3, type: 2},
{id: 4, type: 3}
];
console.log(reversedView(objects).find(o => o.type === 2));