const allocation = [
{partner: 3},
{partner: 1},
{partner: 2},
{partner: 0},
{partner: 4}
];
const rightallocation = new Array(5);
rightallocation.fill({number: 1});
for (let i = 0; i < allocation.length; i++) {
const rightIndex = allocation[i].partner;
rightallocation[rightIndex].number = i;
console.log("Filling "+ (i) + " into rightallocation["+ (allocation[i].partner)+"]");
console.log(rightallocation[allocation[i].partner]);
}
console.log(rightallocation);
This script is designed to mirror the 'allocation' array. For example, if allocation[0] = 3, then rightallocation[3] should equal 0. Although all logs within the loop display correct numbers, the resultant array consists of mostly number:4 entries (last index).