How i can remove or replace an value from array in for

window.component = [];
iddd = 0;

function add_array(id, component) {
  window.component[iddd] = new Array(id, component);
  iddd++;
}

add_array(0, 1);
add_array(0, 1);
add_array(1, 1);

for (n = 0; n < window.component.length; n++) {
  if (window.component[n]) {
    console.log(window.component[n][0] + ':' + window.component[n][1]);
  }
}

So i have that code.
Output:

0:1
0:1
1:1

With add_array i create a new array.
I created a for with window.component.length to get all arrays i created.
But the problem is, when i add two or more arrays with the same id add_array(id my code will read the dublicate.
What i want to do is when i add three arrays

add_array(0, 1);
add_array(0, 2);
add_array(0, 3);

only last array add_array(0, 3); to be validated.
And if is

add_array(0, 1);
add_array(0, 2);
add_array(0, 3);
add_array(1, 2);
add_array(3, 4);

Output will be

0:3
1:2
3:4

Thank you for your time, please help me with that idea!

Answer

Use an object instead of an array, indexed by id.

window.components = [];
function add_array(id, component) {
    window.components[id] = [id, component];
}

add_array(0, 1);
add_array(0, 2);
add_array(0, 3);
add_array(1, 2);
add_array(3, 4);

for (const [id, component] of Object.values(window.components)) {
    console.log(id + ':' + component);
}