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 code should take the array 'allocation' and mirror it. e.g. allocation[0] = 3, so rightallocation[3]= 0. All my logs inside the for give the correct numbers, but i get an array that is full of number:4 (last index)